public
Last active

How to publish packages to NPM

  • Download Gist
readme.md
Markdown

Getting Started with NPM (as a developer)

If you haven't already set your NPM author info, now you should:

npm set init.author.name "Your Name"
npm set init.author.email "you@example.com"
npm set init.author.url "http://yourblog.com"

npm adduser

Then create a package.json and publish it:

cd /path/to/your-project
npm init

npm install -g pakmanager
# this shows you dependencies as you `require`d them
pakmanager deps
# now edit `package.json` and add any deps you forgot about

npm publish ./

More Info:

Appendix:

If you haven't already installed npm, or you'd like the latest version:

OS X

curl http://npmjs.org/install.sh | sh

Linux

curl http://npmjs.org/install.sh | sudo sh

This should be added to NPM docs!

How we can create a npm module with test folder and run test with npm test?
For example, test.js

var assert = require('assert'),
    addmodule = require('../../add');

addmodule.add(
    1, 
    function (err, data) {
        assert.ok(data);
    }
);

If I have test.js inside test folder. Does above code of test.js will be run with command npm test in node packaged module?

All you need to do is to add a script attribute in package.json, e.g., add following attribute

{
"name" : "...",
...
"scripts": {
    "test": "node ./test/test"
  }
}

:) awesome, thank you, my first npm just deployed

edit (4 months alter): awesome, helped me again :-) ! thanks

Amazing. This ought to be the no.1 hit on Google for deploying NPM packages. Thanks.

Thanks, it helped me a lot!

When doing npm adduser, I got an error saying "Error: default value must be string or number", so I had to edit /home/username/.npmrc to only have:

email = foo@bar.com

Credit: https://github.com/npm/npm/issues/4363#issuecomment-31074497.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.