npm

Topics related to npm:

Getting started with npm

npm is the default package manager for Node.js. It is written entirely in JavaScript, and allows to install and distribute mostly JavaScript modules on the registry. Packages are treated in the CommonJS format, and are recognizable by the presence of a package.json file.

Publishing

npm scripts

Pre-recognized scripts

  • prepublish: Run before the package is published
  • publish, postpublish: Run after the package is published
  • preinstall: Run before the package is installed
  • install, postinstall: Run after the package is installed
  • preversion, version: Run before bump the package version
  • postversion: Run after bump the package version
  • pretest, test, posttest: Run by the npm test command
  • prestop, stop, poststop: Run by the npm stop command
  • prestart, start, poststart: Run by the npm start command
  • prerestart, restart, postrestart: Run by the npm restart command. Note: npm restart will run the stop and start scripts if no restart script is provided.

It can be deduced that the "scripts" property in package.json is a very powerful tool. It can be used as a build tool, similar to the likes of Grunt and Gulp, but with over 250,000 packages available. NPM scripts runs npm packages installed locally to your project from the node_modules/.bin directory.

What NPM does ?