Publish a module to NPM

Publish a module to NPM

This article is based on this publiation.

To publish to npm, being logged in is required:

npm login

The package to be published must be contained in its own directory, which must include a package.json file

The package.json file must contain at least the following information:

{
  "name": "@USERNAME/MODULE_NAME",
  "version": "0.0.1"
  "main": "FILE.js",
}

where USERNAME is the username of registered npmjs.com account, MODULE_NAME is the name of the module to publish and FILE.js the main file of the module.

Additionally, the version must be set to the X.Y.Z format

npm publish --access=public

The content of node_modules is automatically ignored so dependencies can be added easily using

npm install --save DEPENDENCY_NAME