How to create new module in npm
base on the websethttp://www.hacksparrow.com/create-npm-package-node-js-module.html
1、Addtwoconfigurefile
Youshouldaddtwoconfigurefileinyouproject,theyarepackage.jsonandREADME.mdfiles.
package.jsonlikethis:
{
"name": "myweb",
"version": "0.0.1",
"description": "Node.js module to do some thing",
"preferGlobal": "true",
"main": "index.js",
"bin": { "myweb": "index.js" },
"author": "Danhuang",
"keywords": ["myweb", "nodejs", "nodejs framework"],
"repository" : {
"type": "git",
"url": "https://[email protected]/tnodejs/myweb-nodejs.git"
},
"dependencies": {
"commander": "0.5.2"
},
"engines": { "node": "*" }
}
Sincewe'dwantmywebtobeusedasacommandlinetool,wehaveset"preferGlobal":"true"and"bin":{"myweb":"index.js"}.Ifitwerealibrarymodule,thatwouldnothavebeenrequired.
Youmustcheckthatthenameisyourprojectname,andurlintherepositorythatwecanaccesstotheprojectcodeingithub.
README.mdisthe'introductionandguidefile'fortheproject,formattedinGitHubflavoredMarkdown(http://github.github.com/github-flavored-markdown/).
2、Youcanaddmoduleinlinux,windows,mac.
A.cdmywebdirectoryandrunnpmlink
npm link
B.Ifitthrowthepermissiondenie,thenyoucabrunthesudonpmlink
sudo npm link
C.Afterthatwewillfindanewfloderwhichnameis'node_modules'inmywebdirectory.
D.Butwedon'twantitscontentstobepartofthegitrepository,solet'saddnode_modulesto.gitignore.
echo node_modules/ >> .gitignore
E.Nowweshouldaddautornameandpassword.
Then,youwillinputyourname,passwordandemail.
npm adduser
F.Afterallofthestep,wecanpublishthenodejsmodule.
npm publish
3、Testforthenpmmodule
Wecanusenpminstallthemodulethatwehadaddedbefore.
npminstallmyweb
Afterruningtheit,wewillfindourmodule(myweb)stayinthenode_modulesfloder.
上一篇: css3动画实现loading
下一篇: iPad2新机设置大全攻略
推荐阅读
-
How to Initialize a New MySQL Installation and Create New Da_MySQL
-
How to Initialize a New MySQL Installation and Create New Da_MySQL
-
Delphi Open Tools API - How to create and add new menu item
-
Create new module “HelloWorld” – in Magento
-
How to create a new object in Windchill with IBAs
-
How to solve "Error: Cannot find module '../lib/cli'" when create a new project by webstorm.
-
How to create new geodatabases
-
How to create new module in npm
-
How to create a new package / theme (文档下载)
-
How to automate Microsoft Word to create a new document by using Visual C#