Basic Node JS and NPM Commands

Following are some useful commands for Node.js and NPM.

Node

Display Node.js version.

$ node --version

Run local NPM package. If the package is installed globally, don’t need to use ‘node’ command.

$ node run <npm_package_command>

NPM

Display NPM version.

$ npm --version

Interactively create a package.json file.

$ npm init

Install package globally.

$ npm install -g <module(s)>;

Install package locally and save the dependency to package.json.

$ npm install <module(s)> --save-dev

Install package(s) based on package.json file in the current folder.

$ npm install

List global packages with depth = 0.

$ npm ls -g -depth=0

List global packages detail with depth = 0.

$ npm ls -gl -depth=0

List local packages with depth = 0.

$ npm ls -depth=0

List local packages detail with depth = 0.

$ npm ls -l -depth=0

Search the registry for packages matching the search terms.

$ npm search <module>

Update global packages.

$ npm update -g

Update local packages.

$ npm update

Uninstall global package.

$ npm uninstall -g &amp;lt;module(s)&amp;gt;

Uninstall local package.

$ npm uninstall &amp;lt;module(s)&amp;gt;

Run NPM tasks defined in ‘scripts’ section of ‘package.json’ file. ‘start’ and ‘test’ scripts don’t need ‘run’ command.

$ npm run <script_task>
$ npm start

NPM run scripts boilerplate:
https://gist.github.com/addyosmani/9f10c555e32a8d06ddb0

Leave a comment