Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 15, 2022 09:49 pm GMT

Basic NPM Commands

After setting up n node.js development environment, you need to know some basic commands of node package manager npm. The followings are the most commonly used ones.

npm stands for node package manager.

Installing npm

npm comes with the node.js. You can install node.js from their official website https://nodejs.org/en/download/
After installing node, You can check the version of node and npm by running the following commands:

node -v
npm -v

Flags

-S is the same as --save, and -D is the same as --save-dev.

npm init

Initializes the package.json file of a project.

Use the -y flag to skip the questions and to create a package.json using default values.

npm install

Installs the dependencies listed in package.json.

Shorthand: npm i

npm install <package>

Installs a package from the npm registry.

Shorthand: npm i <package>

npm install -g <package>

Installs a package globally on your machine.

npm install <package-name@version-number>

Install a specific package version rather than the most latest version.

npm uninstall <package>

Like the command itself suggests, it uninstalls packages that are already installed.

Shorthand: npm uninstall

npm uninstall -g <package>

Uninstalls a global package from your machine.

npm outdated

List the outdated packages for upgrade

npm update <package>

Updates the specified package to the latest version available. If package is not specified, it updates every package.

npm cache verify

Check how many cache entries are available.

Shorthand: npm up <package>

npm cache clean force

Clears the npm cache

npm audit

Performs a security check for all the available project packages.

npm update -g <package>

Updates a global package to the latest version available.

npm list

Lists all the installed packages and their versions, along with their dependencies in a tree structure.

npm list depth <number>

To get packages of a certain depth.
The packages installed by you will be in the depth 0. Its dependencies will be in the depth 1 and further dependencies will be in the depth 2 and so on.

npm view <package> <version>

Shows available details about the specified package. If the version is not set, it defaults to the latest version.

npm run <script>

Executes the specified script, if found as a property of the script object in package.json.

npm help

npm CLI has built in help command

npm help <term>Flags

-S is the same as --save, and -D is the same as --save-dev.

Tries to show the appropriate documentation page for the term provided.

npm <command> -h

To get help for a particular command.

npm help-search <command>

To search npm documentation for help.

npm ci

This installs packages from package-lock.json without updating the dependency tree.

npm rebuild

Rebuild packages

npm version major

Find a major version

npm version minor

Find a minor version

npm version patch

Find the patch version

Conclusion

This list is not exhaustive. I welcome any criticism,advice and contribution involving this work in the comments below.


Original Link: https://dev.to/bikocodes/basic-npm-commands-1n9j

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To