Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
How to publish packages to NPM

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 ./

Beta and Release versions

If you don't want something to install by default

npm publish ./ --tag beta

If you published a bugfix as v1.0.7 and need to set v1.1.3 back to latest

git checkout v1.0.7
npm publish ./
   
git checkout v1.1.3
npm tag foobar@1.1.3 latest

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!

n1k0 commented Feb 2, 2013

+1

+1

reiz commented Jul 14, 2013

+1

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"
  }
}

ondrek commented Nov 3, 2013

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

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

nice

HashanP commented Dec 22, 2013

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

thanks!

amytych commented Feb 21, 2014

Thanks, it helped me a lot!

mom! I published a package :)
https://www.npmjs.org/package/googlebot

Thanks man!

plouc commented Mar 29, 2014

+1

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: npm/npm#4363 (comment).

ixisio commented May 7, 2014

+1 Great docs

itomg commented Jun 12, 2014

+1

yeah ! great docs ! I published my npm module successfully with this docs πŸ‘

+1 Thanks a lot

evaisse commented Jul 4, 2014

+1 WΓΌnderbar

+1

Thanks!!!

Thanks! I published my first npm module with your doc :)

+another 1

+1, just published my first module. so easy.

+1, also mind owners commands to manage maintainers

I get error on pakmanager [ERROR] The following packages arerequired, but not in the package, nor on npm when trying to upload.

πŸ‘

alahlali commented May 4, 2015

+1

jperler commented Jun 17, 2015

+1

lenage commented Jun 25, 2015

πŸ‘

mudcube commented Jul 6, 2015

+1 Thanks ;)

πŸ‘

dhowe commented Sep 13, 2015

I get the following warning on 'pakmanager deps':

======================= WARNING =======================
Assuming browser mode by default is deprecated.
  Include browserDependencies in your package.json
  -- OR --
  pakmanager -e browser build

In the next release of pakmanager, the node environment will be assumed as default
=======================================================


Targeted Environment: browser
[[[deps]]]

@coolaj86 Hey I have published a module gogit. But it's not working. Do I need to include node_modules when publishing.
The error says it's not able to find the module octonode (which is in my devDependencies)

bennyn commented Nov 10, 2015

Good tutorial but when I execute pakmanager deps then I also receive:

======================= WARNING =======================
Assuming browser mode by default is deprecated.
  Include browserDependencies in your package.json
  -- OR --
  pakmanager -e browser build

In the next release of pakmanager, the node environment will be assumed as default
=======================================================


Targeted Environment: browser
[[[deps]]]

To I need to declare my dependencies now as browserDependencies like shown in this description?

agl0809 commented Dec 1, 2015

πŸ‘

blin17 commented Feb 19, 2016

Also adding a badge into your readme is a pretty neat addition too https://badge.fury.io/

If you're tagging versions, try npm version major|minor|patch which intelligently increments the version number and creates a git tag and package.json version bump.

πŸ‘

Is it possible to publish directly from a GitHub repository (as opposed to publishing from a local machine)? or better said, I'm not able to figure out how to do this... https://docs.npmjs.com/all#repository seems to indicate that the repository can be referenced/extracted from GitHub...

http://stackoverflow.com/questions/35026096/is-it-possible-to-publish-to-npm-directly-from-a-github-repository

πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘πŸ‘

P.S. The first two links in the More Info section are broken

Obooman commented Mar 29, 2016

Cool work!Thanks.

Is it compulsory to provide a test in publishing a npm package ?

Very handy. Thanks πŸ‘

πŸ‘

πŸ‘

zhangbg commented Nov 30, 2016

mark.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment