Instantly share code, notes, and snippets.

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

This comment has been minimized.

silviu-burcea commented Feb 1, 2013

This should be added to NPM docs!

@n1k0

This comment has been minimized.

n1k0 commented Feb 2, 2013

+1

@muhammadghazali

This comment has been minimized.

muhammadghazali commented Feb 15, 2013

@sorribas

This comment has been minimized.

sorribas commented Jun 26, 2013

+1

@reiz

This comment has been minimized.

reiz commented Jul 14, 2013

+1

@justin-john

This comment has been minimized.

justin-john commented 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?

@kamrulislam

This comment has been minimized.

kamrulislam commented 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"
  }
}
@ondrek

This comment has been minimized.

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.

FvckSh1t commented Nov 25, 2013

nice

@hashanp

This comment has been minimized.

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.

kumarharsh commented Feb 19, 2014

thanks!

@amytych

This comment has been minimized.

amytych commented Feb 21, 2014

Thanks, it helped me a lot!

@dvidsilva

This comment has been minimized.

dvidsilva commented Feb 25, 2014

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

@FireZenk

This comment has been minimized.

FireZenk commented Feb 28, 2014

Thanks man!

@plouc

This comment has been minimized.

plouc commented Mar 29, 2014

+1

@Munawwar

This comment has been minimized.

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

@ixisio

This comment has been minimized.

ixisio commented May 7, 2014

+1 Great docs

@itomg

This comment has been minimized.

itomg commented Jun 12, 2014

+1

@scriptnull

This comment has been minimized.

scriptnull commented Jun 24, 2014

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

@nitriques

This comment has been minimized.

nitriques commented Jun 27, 2014

+1 Thanks a lot

@evaisse

This comment has been minimized.

evaisse commented Jul 4, 2014

+1 WΓΌnderbar

@nikulkarni

This comment has been minimized.

nikulkarni commented Jul 24, 2014

+1

@MuhammadReda

This comment has been minimized.

MuhammadReda commented Aug 17, 2014

+1

@roman-kaspar

This comment has been minimized.

roman-kaspar commented Sep 5, 2014

+1

@rain1024

This comment has been minimized.

rain1024 commented Dec 19, 2014

+1

@sebabelmar

This comment has been minimized.

sebabelmar commented Jan 20, 2015

Thanks!!!

@gserrano

This comment has been minimized.

gserrano commented Jan 27, 2015

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

@AllThingsSmitty

This comment has been minimized.

AllThingsSmitty commented Feb 20, 2015

+1

@kachizukanne

This comment has been minimized.

kachizukanne commented Mar 2, 2015

+another 1

@jacobludriks

This comment has been minimized.

jacobludriks commented Mar 5, 2015

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

@flockonus

This comment has been minimized.

flockonus commented Mar 6, 2015

+1, also mind owners commands to manage maintainers

@CosmicWebServices

This comment has been minimized.

CosmicWebServices commented 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.

@siyangYao

This comment has been minimized.

siyangYao commented Apr 3, 2015

πŸ‘

@alahlali

This comment has been minimized.

alahlali commented May 4, 2015

+1

@jperler

This comment has been minimized.

jperler commented Jun 17, 2015

+1

@lenage

This comment has been minimized.

lenage commented Jun 25, 2015

πŸ‘

@mudcube

This comment has been minimized.

mudcube commented Jul 6, 2015

+1 Thanks ;)

@musamusa

This comment has been minimized.

musamusa commented Aug 17, 2015

πŸ‘

@dhowe

This comment has been minimized.

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.

akashnimare commented 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)

@bennyn

This comment has been minimized.

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.

agl0809 commented Dec 1, 2015

πŸ‘

@m31271n

This comment has been minimized.

m31271n commented Jan 27, 2016

@blin17

This comment has been minimized.

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.

danawoodman commented 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.

@rkawajan

This comment has been minimized.

rkawajan commented Mar 19, 2016

πŸ‘

@autopulous

This comment has been minimized.

autopulous commented 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

@Obooman

This comment has been minimized.

Obooman commented Mar 29, 2016

Cool work!Thanks.

@abdghani

This comment has been minimized.

abdghani commented Apr 10, 2016

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

@andreafalzetti

This comment has been minimized.

andreafalzetti commented Apr 12, 2016

Very handy. Thanks πŸ‘

@avaleriani

This comment has been minimized.

avaleriani commented Apr 16, 2016

πŸ‘

@AmmarHasan

This comment has been minimized.

AmmarHasan commented Jul 22, 2016

+1

@paradigmist

This comment has been minimized.

paradigmist commented Aug 2, 2016

πŸ‘

@zhangbg

This comment has been minimized.

zhangbg commented Nov 30, 2016

mark.

@mortezakarimi

This comment has been minimized.

mortezakarimi commented Aug 9, 2017

+1 πŸ‘

@alexandlazaris

This comment has been minimized.

alexandlazaris commented 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 πŸ€”

@nuno-nlfsoftware

This comment has been minimized.

nuno-nlfsoftware commented Sep 27, 2017

πŸ‘

@jonathanarbely

This comment has been minimized.

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.

xizon commented Feb 2, 2018

nice!!

@ryanburnette

This comment has been minimized.

ryanburnette commented Feb 12, 2018

Can you update this to include horse-npm?

@chattes

This comment has been minimized.

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.

alalbers commented Feb 28, 2018

+100

@AugustoAleGon

This comment has been minimized.

AugustoAleGon commented Mar 27, 2018

I got the same problem!! @chattes

@talentedandrew

This comment has been minimized.

talentedandrew commented Apr 21, 2018

Published my first npm package react-modern-datepicker

@PetrSnobelt

This comment has been minimized.

PetrSnobelt commented Aug 15, 2018

to add linked github repo add repo section to package.json

@hustcc

This comment has been minimized.

hustcc commented Nov 6, 2018

npm-robbery A command tool to register npm package name conveniently.

@nakulkundra

This comment has been minimized.

nakulkundra commented Nov 13, 2018

@markolofsen

This comment has been minimized.

markolofsen commented Dec 12, 2018

It's really easy if are you using special tool for publications.
It's works in your browser, without any special dependencies.

Try this library for that https://github.com/markolofsen/how_to_upload_package_to_npm

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