Thursday, 22 January 2015

make your npm package and publish to others to use

If you created some functions you want to share your friends to use, however, you don't want copy your source code to them, not only because your are mean, but also you may upgrade your code and you don't want copy copy copy copy copy and copy to her to he to her to her ...

Let me show you how to publish to npm and your friends can use your code as they use expressjs (just put the dependency in your package.json and run npm install).

First, create a npm project:

Second,  publish:

So, you can see you need an account for npm, to do this you need access: and signup:

Then add your user:

Then run npm publish again:

You may get this error as I did above:

npm ERR! forbidden user: *you can't see my account* not authorized to modify npmtest

The reason is 'npmtest' is used by someone else.

Change the name in package.json file, and change it to a rubbish name, like xxadfasdfafewfwef.

Then, run "npm publish"

Well done:

No comments:

Post a comment