Create a gist now

Instantly share code, notes, and snippets.

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 should be added to NPM docs!

@n1k0
n1k0 commented Feb 2, 2013

+1

@sorribas

+1

@reiz
reiz commented Jul 14, 2013

+1

@justin-john

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

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
ondrek commented Nov 3, 2013

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

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

@Fritz-Lium

nice

@HashanP
HashanP commented Dec 22, 2013

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

@kumarharsh

thanks!

@amytych
amytych commented Feb 21, 2014

Thanks, it helped me a lot!

@dvidsilva

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

@FireZenk

Thanks man!

@plouc
plouc commented Mar 29, 2014

+1

@Munawwar

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
ixisio commented May 7, 2014

+1 Great docs

@itomg
itomg commented Jun 12, 2014

+1

@scriptnull

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

@nitriques

+1 Thanks a lot

@evaisse
evaisse commented Jul 4, 2014

+1 WΓΌnderbar

@nikulkarni

+1

@MuhammadReda

+1

@roman-kaspar

+1

@rain1024

+1

@sebabelmar

Thanks!!!

@gserrano

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

@kachizukanne

+another 1

@jacobludriks

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

@flockonus

+1, also mind owners commands to manage maintainers

@CosmicWebServices

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

@siyangYao

πŸ‘

@lahlali
lahlali commented May 4, 2015

+1

@jperler
jperler commented Jun 17, 2015

+1

@lenage
lenage commented Jun 25, 2015

πŸ‘

@mudcube
mudcube commented Jul 6, 2015

+1 Thanks ;)

@musamusa

πŸ‘

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

@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
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
agl0809 commented Dec 1, 2015

πŸ‘

@blin17
blin17 commented Feb 19, 2016

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

@danawoodman

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

πŸ‘

@autopulous

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
Obooman commented Mar 29, 2016

Cool work!Thanks.

@abdghani

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

@andreafalzetti

Very handy. Thanks πŸ‘

@avaleriani

πŸ‘

@AmmarHasan

+1

@paradigmist

πŸ‘

@zhangbg
zhangbg commented Nov 30, 2016

mark.

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