Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.
When you install a package using npm into your node_modules folder, or also globally, how do you use it in your Node code?
Say you install lodash, the popular JavaScript utility library, using
npm install lodash
This installs the package in the local node_modules folder.
To use it in your code, you just need to import it into your program using require:
const _ = require('lodash')
What if your package is an executable?
In that case, the executable is placed in node_modules/.bin/.
For example, cowsay provides a CLI:
The cowsay package provides a command line program that can be executed to make a cow say something (and other animals as well 🦊).
Running npm install cowsay installs the package and its dependencies in node_modules:

There is a hidden .bin folder, which contains symbolic links to the cowsay binaries:

How do you execute those?
You can run ./node_modules/.bin/cowsay, but npx (included in npm since 5.2) is simpler:
npx cowsay
npx finds and runs the package.
