• Bytes Route logo


NPM is an acronym for the node package manager. It is the largest software registry in the world. It has three roles, to install packages or modules, to host, and to run tasks. We will be exploring the cowsay package.


As the CLI tool, it installs the packages defined in package.json and package-lock.json into the node_modules folder. Due to the dependencies being already declared in the two files, is a good practice to commit both of them to the source control.

Committing the node_modules folder to the source control is a bad practice. You can always use the npm tool to install all the modules from scratch. The folder is very large too so you might have limits on the source control server. The folder should be added to .gitignore file.

npm install cowsay


All of the modules are stored in the registry the largest public database in the world. You interact with the registry through the CLI or through the website. You can use the website for exploring packages, sharing, or collaboration with other people. Explore the cowsay package.

Task runner

Another useful feature is that you can declare tasks inside the package.json file, under scripts and the npm CLI can run it for you. It comes in handy for preparing your project, testing, deploying, building, or running it.

All tasks all called via ‘npm run ...’ with the task name except ‘start’ and ‘test’ (npm start and npm test). These special tasks can be customized too and do not require ‘run’.

You can combine other CLI's or npm tasks via && or ||. Use && for concurrent running and || for parallel runs of tasks.

Building on top the task runner is the npx command, this lets you:

npx cowsay mooo

Using npx this way means that you want to install the package and run it with the commands specified.

For more tips and tricks check out: npm tricks @ freecodecamp