Texts | Christofer Sandin

Terminal: npm

Terminal: npm

Notice: This is a little "terminal treat" – a short tip rather than a whole article. Enjoy!

Working in the terminal with web development, you’ll likely be running into Node and the Node Package Manager (npm) sooner or later. It’s a standardized way to install and use JavaScript-based software — here’s a summary of some useful commands.

Packages can be installed globally or per project.

Global packages

  • List all globally installed packages
    npm list -g --depth=0

  • You can check for a particular module installed globally. This is particularly useful when checking what version of a module you are using globally (remove the -g flag if checking a local module):
    npm list -g --depth=0 | grep <module_name>

Packages

  • If you’d like to see all available (remote) versions for a particular module, then do:
    npm view <module_name> versions.
    Note that versions is in the plural. This will give you a complete listing of versions to choose from.

  • For the latest remote version:
    npm view <module_name> version  
    Note that the version is singular.

  • To find out which packages need to be updated, you can use
    npm outdated -g --depth=0

  • To update global packages, you can use
    npm install -g <package>

  • To update all global packages, you can use:
    npm update -g

Another way would be to use npm-check-updates (or ncu for short).

References