NodeJS - Install a NodeJS package using the npm install command
by
Jeremy Canfield |
Updated: May 22 2023
| NodeJS articles
The npm install (Node Package Manager) command can be used to install a NodeJS package. In this example, the cors package is installed.
npm install cors
In this example, the latest version of the dotenv package is installed.
npm install dotenv@latest
Here is how you can install a specific version of a package.
npm install express@4.17.3
The -g or --global flag can be used for a global install (all users).
npm install --global node-fetch
Or, you can add the package you want to install to package.json.
{
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.0.0",
"express": "^4.17.3",
"node-fetch": "^3.2.1"
}
}
The npm install command should then install or update the packages listed in package.json.
~]$ npm install
added 64 packages, and audited 65 packages in 3s
10 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
npm notice
npm notice New minor version of npm available! 9.5.1 -> 9.6.4
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.6.4
npm notice Run npm install -g npm@9.6.4 to update!
npm notice
Did you find this article helpful?
If so, consider buying me a coffee over at