Skip to content
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

+1

@reiz

+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

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

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

@Fritz-Lium

nice

@HashanP

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

@kumarharsh

thanks!

@amytych

Thanks, it helped me a lot!

@dvidsilva

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

@FireZenk

Thanks man!

@plouc

+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

+1 Great docs

@itomg

+1

@scriptnull

yeah ! great docs ! I published my npm module successfully with this docs :+1:

@nitriques

+1 Thanks a lot

@evaisse

+1 Wünderbar

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

@lahlali

+1

@jperler

+1

@mudcube

+1 Thanks ;)

@dhowe

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

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.