You should add two configure file in you project, they are package.json and README.md files.
package.json like this:
{ "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": "*" } }
Since we'd want myweb to be used as a commandline tool, we have set "preferGlobal": "true" and "bin": { "myweb": "index.js" }. If it were a library module, that would not have been required.
You must check that the name is your project name, and url in the repository that we can access to the project code in github.
README.md is the 'introduction and guide file' for the project, formatted in GitHub flavored Markdown(http://github.github.com/github-flavored-markdown/).
A. cd myweb directory and run npm link
npm link
B. If it throw the permission denie, then you cab run the sudo npm link
sudo npm link
C. After that we will find a new floder which name is 'node_modules' in myweb directory.
D. But we don't want its contents to be part of the git repository, so let's add node_modules to.gitignore.
echo node_modules/ >> .gitignore
E. Now we should add autor name and password.
Then, you will input your name, password and email.
npm adduser
F. After all of the step, we can publish the nodejs module.
npm publish
We can use npm install the module that we had added before.
npm install myweb
After runing the it, we will find our module(myweb) stay in the node_modules floder.