Create a gist now

Instantly share code, notes, and snippets.

Embed
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
@silviu-burcea

This comment has been minimized.

Show comment
Hide comment
@silviu-burcea

silviu-burcea Feb 1, 2013

This should be added to NPM docs!

This should be added to NPM docs!

@n1k0

This comment has been minimized.

Show comment
Hide comment
@n1k0

n1k0 Feb 2, 2013

+1

n1k0 commented Feb 2, 2013

+1

@muhammadghazali

This comment has been minimized.

Show comment
Hide comment
@sorribas

This comment has been minimized.

Show comment
Hide comment
@sorribas

sorribas Jun 26, 2013

+1

+1

@reiz

This comment has been minimized.

Show comment
Hide comment
@reiz

reiz Jul 14, 2013

+1

reiz commented Jul 14, 2013

+1

@justin-john

This comment has been minimized.

Show comment
Hide comment
@justin-john

justin-john Jul 18, 2013

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?

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?

@kamrulislam

This comment has been minimized.

Show comment
Hide comment
@kamrulislam

kamrulislam Sep 21, 2013

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

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

This comment has been minimized.

Show comment
Hide comment
@ondrek

ondrek Nov 3, 2013

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

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

ondrek commented Nov 3, 2013

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

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

@FvckSh1t

This comment has been minimized.

Show comment
Hide comment
@FvckSh1t

FvckSh1t Nov 25, 2013

nice

nice

@hashanp

This comment has been minimized.

Show comment
Hide comment
@hashanp

hashanp Dec 22, 2013

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

hashanp commented Dec 22, 2013

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

@kumarharsh

This comment has been minimized.

Show comment
Hide comment
@kumarharsh

kumarharsh Feb 19, 2014

thanks!

thanks!

@amytych

This comment has been minimized.

Show comment
Hide comment
@amytych

amytych Feb 21, 2014

Thanks, it helped me a lot!

amytych commented Feb 21, 2014

Thanks, it helped me a lot!

@dvidsilva

This comment has been minimized.

Show comment
Hide comment
@dvidsilva

dvidsilva Feb 25, 2014

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

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

@FireZenk

This comment has been minimized.

Show comment
Hide comment
@FireZenk

FireZenk Feb 28, 2014

Thanks man!

Thanks man!

@plouc

This comment has been minimized.

Show comment
Hide comment
@plouc

plouc Mar 29, 2014

+1

plouc commented Mar 29, 2014

+1

@Munawwar

This comment has been minimized.

Show comment
Hide comment
@Munawwar

Munawwar Apr 10, 2014

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

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

This comment has been minimized.

Show comment
Hide comment
@ixisio

ixisio May 7, 2014

+1 Great docs

ixisio commented May 7, 2014

+1 Great docs

@itomg

This comment has been minimized.

Show comment
Hide comment
@itomg

itomg Jun 12, 2014

+1

itomg commented Jun 12, 2014

+1

@scriptnull

This comment has been minimized.

Show comment
Hide comment
@scriptnull

scriptnull Jun 24, 2014

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

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

@nitriques

This comment has been minimized.

Show comment
Hide comment
@nitriques

nitriques Jun 27, 2014

+1 Thanks a lot

+1 Thanks a lot

@evaisse

This comment has been minimized.

Show comment
Hide comment
@evaisse

evaisse Jul 4, 2014

+1 WΓΌnderbar

evaisse commented Jul 4, 2014

+1 WΓΌnderbar

@nikulkarni

This comment has been minimized.

Show comment
Hide comment
@nikulkarni

nikulkarni Jul 24, 2014

+1

+1

@MuhammadReda

This comment has been minimized.

Show comment
Hide comment
@MuhammadReda

MuhammadReda Aug 17, 2014

+1

+1

@roman-kaspar

This comment has been minimized.

Show comment
Hide comment
@roman-kaspar

roman-kaspar Sep 5, 2014

+1

+1

@rain1024

This comment has been minimized.

Show comment
Hide comment
@rain1024

rain1024 Dec 19, 2014

+1

+1

@sebabelmar

This comment has been minimized.

Show comment
Hide comment
@sebabelmar

sebabelmar Jan 20, 2015

Thanks!!!

Thanks!!!

@gserrano

This comment has been minimized.

Show comment
Hide comment
@gserrano

gserrano Jan 27, 2015

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

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

@AllThingsSmitty

This comment has been minimized.

Show comment
Hide comment
@AllThingsSmitty

AllThingsSmitty Feb 20, 2015

+1

@kachizukanne

This comment has been minimized.

Show comment
Hide comment
@kachizukanne

kachizukanne Mar 2, 2015

+another 1

+another 1

@jacobludriks

This comment has been minimized.

Show comment
Hide comment
@jacobludriks

jacobludriks Mar 5, 2015

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

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

@flockonus

This comment has been minimized.

Show comment
Hide comment
@flockonus

flockonus Mar 6, 2015

+1, also mind owners commands to manage maintainers

+1, also mind owners commands to manage maintainers

@CosmicWebServices

This comment has been minimized.

Show comment
Hide comment
@CosmicWebServices

CosmicWebServices Mar 13, 2015

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

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

@siyangYao

This comment has been minimized.

Show comment
Hide comment
@siyangYao

siyangYao Apr 3, 2015

πŸ‘

πŸ‘

@alahlali

This comment has been minimized.

Show comment
Hide comment
@alahlali

alahlali May 4, 2015

+1

alahlali commented May 4, 2015

+1

@jperler

This comment has been minimized.

Show comment
Hide comment
@jperler

jperler Jun 17, 2015

+1

jperler commented Jun 17, 2015

+1

@lenage

This comment has been minimized.

Show comment
Hide comment
@lenage

lenage Jun 25, 2015

πŸ‘

lenage commented Jun 25, 2015

πŸ‘

@mudcube

This comment has been minimized.

Show comment
Hide comment
@mudcube

mudcube Jul 6, 2015

+1 Thanks ;)

mudcube commented Jul 6, 2015

+1 Thanks ;)

@musamusa

This comment has been minimized.

Show comment
Hide comment
@musamusa

musamusa Aug 17, 2015

πŸ‘

πŸ‘

@dhowe

This comment has been minimized.

Show comment
Hide comment
@dhowe

dhowe 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]]]

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]]]

@akashnimare

This comment has been minimized.

Show comment
Hide comment
@akashnimare

akashnimare Oct 4, 2015

@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)

@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

This comment has been minimized.

Show comment
Hide comment
@bennyn

bennyn 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?

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

This comment has been minimized.

Show comment
Hide comment
@agl0809

agl0809 Dec 1, 2015

πŸ‘

agl0809 commented Dec 1, 2015

πŸ‘

@m31271n

This comment has been minimized.

Show comment
Hide comment
@blin17

This comment has been minimized.

Show comment
Hide comment
@blin17

blin17 Feb 19, 2016

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

blin17 commented Feb 19, 2016

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

@danawoodman

This comment has been minimized.

Show comment
Hide comment
@danawoodman

danawoodman Mar 17, 2016

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.

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.

@rkawajan

This comment has been minimized.

Show comment
Hide comment
@rkawajan

rkawajan Mar 19, 2016

πŸ‘

πŸ‘

@autopulous

This comment has been minimized.

Show comment
Hide comment
@autopulous

autopulous Mar 27, 2016

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

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

This comment has been minimized.

Show comment
Hide comment
@Obooman

Obooman Mar 29, 2016

Cool work!Thanks.

Obooman commented Mar 29, 2016

Cool work!Thanks.

@abdghani

This comment has been minimized.

Show comment
Hide comment
@abdghani

abdghani Apr 10, 2016

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

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

@andreafalzetti

This comment has been minimized.

Show comment
Hide comment
@andreafalzetti

andreafalzetti Apr 12, 2016

Very handy. Thanks πŸ‘

Very handy. Thanks πŸ‘

@avaleriani

This comment has been minimized.

Show comment
Hide comment
@avaleriani

avaleriani Apr 16, 2016

πŸ‘

πŸ‘

@AmmarHasan

This comment has been minimized.

Show comment
Hide comment
@AmmarHasan

AmmarHasan Jul 22, 2016

+1

+1

@paradigmist

This comment has been minimized.

Show comment
Hide comment
@paradigmist

paradigmist Aug 2, 2016

πŸ‘

πŸ‘

@zhangbg

This comment has been minimized.

Show comment
Hide comment
@zhangbg

zhangbg Nov 30, 2016

mark.

zhangbg commented Nov 30, 2016

mark.

@mortezakarimi

This comment has been minimized.

Show comment
Hide comment
@mortezakarimi

mortezakarimi Aug 9, 2017

+1 πŸ‘

mortezakarimi commented Aug 9, 2017

+1 πŸ‘

@alexandlazaris

This comment has been minimized.

Show comment
Hide comment
@alexandlazaris

alexandlazaris Aug 11, 2017

I'm having issues publishing my npm package. I added name and email using npm set init.author.name + same for email. After I do npm adduser and login successfully. After this I enter npm publish and get this error:

you do not have permission to publish "auto-reload". Are you logged in as the correct user? : auto-reload

Does this mean I must login as my package-name? (auto-reload) This makes no sense to me πŸ€”

I'm having issues publishing my npm package. I added name and email using npm set init.author.name + same for email. After I do npm adduser and login successfully. After this I enter npm publish and get this error:

you do not have permission to publish "auto-reload". Are you logged in as the correct user? : auto-reload

Does this mean I must login as my package-name? (auto-reload) This makes no sense to me πŸ€”

@nuno-nlfsoftware

This comment has been minimized.

Show comment
Hide comment
@nuno-nlfsoftware

nuno-nlfsoftware Sep 27, 2017

πŸ‘

πŸ‘

@jonathanarbely

This comment has been minimized.

Show comment
Hide comment
@jonathanarbely

jonathanarbely Jan 21, 2018

CMD should be started as admin.
Edit: User Accounts should be created on npmjs.com. Then do npm login. Then publish with npm publish ./.

jonathanarbely commented Jan 21, 2018

CMD should be started as admin.
Edit: User Accounts should be created on npmjs.com. Then do npm login. Then publish with npm publish ./.

@xizon

This comment has been minimized.

Show comment
Hide comment
@xizon

xizon Feb 2, 2018

nice!!

xizon commented Feb 2, 2018

nice!!

@ryanburnette

This comment has been minimized.

Show comment
Hide comment
@ryanburnette

ryanburnette Feb 12, 2018

Can you update this to include horse-npm?

Can you update this to include horse-npm?

@chattes

This comment has been minimized.

Show comment
Hide comment
@chattes

chattes Feb 23, 2018

I published a package to npm but I dont see the linked github repo?
Any ideas?
image

chattes commented Feb 23, 2018

I published a package to npm but I dont see the linked github repo?
Any ideas?
image

@alalbers

This comment has been minimized.

Show comment
Hide comment
@alalbers

alalbers Feb 28, 2018

+100

+100

@AugustoAleGon

This comment has been minimized.

Show comment
Hide comment
@AugustoAleGon

AugustoAleGon Mar 27, 2018

I got the same problem!! @chattes

AugustoAleGon commented Mar 27, 2018

I got the same problem!! @chattes

@talentedandrew

This comment has been minimized.

Show comment
Hide comment
@talentedandrew

talentedandrew Apr 21, 2018

Published my first npm package react-modern-datepicker

Published my first npm package react-modern-datepicker

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