Commonly used npm commands

Manthan Ankolekar - Jun 30 '23 - - Dev Community

Initializing a project

npm init
Enter fullscreen mode Exit fullscreen mode

Installing packages

npm install <package-name>      // Install package locally
npm install -g <package-name>   // Install package globally
npm install --save <package-name>    // Install package and save it as a dependency in package.json
npm install --save-dev <package-name> // Install package and save it as a development dependency in package.json
Enter fullscreen mode Exit fullscreen mode

Uninstalling packages

npm uninstall <package-name>    // Uninstall package locally
npm uninstall -g <package-name> // Uninstall package globally
Enter fullscreen mode Exit fullscreen mode

Running scripts defined in package.json

npm run <script-name>
Enter fullscreen mode Exit fullscreen mode

Updating packages

npm update                     // Update all packages
npm update <package-name>      // Update a specific package
Enter fullscreen mode Exit fullscreen mode

Listing installed packages

npm ls                         // List installed packages
npm ls -g                      // List globally installed packages
Enter fullscreen mode Exit fullscreen mode

Searching for packages

npm search <keyword>           // Search for packages in the npm registry
Enter fullscreen mode Exit fullscreen mode

Viewing package information

npm view <package-name>        // View details about a package
npm view <package-name> versions    // View available versions of a package
Enter fullscreen mode Exit fullscreen mode

Publishing packages

npm publish                    // Publish a package to the npm registry
Enter fullscreen mode Exit fullscreen mode

Managing package versions

npm version <new-version>          // Update the version of your package
Enter fullscreen mode Exit fullscreen mode

Installing packages from a package.json file

npm install                // Install packages listed in package.json
Enter fullscreen mode Exit fullscreen mode

Cleaning the npm cache

npm cache clean            // Clear the entire npm cache
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .