Skip to content

Instantly share code, notes, and snippets.

@VikashSaharan1
Last active March 17, 2019 16:19
Show Gist options
  • Save VikashSaharan1/7e14360ac407a6784a0f456e3bd68387 to your computer and use it in GitHub Desktop.
Save VikashSaharan1/7e14360ac407a6784a0f456e3bd68387 to your computer and use it in GitHub Desktop.
Most useful NPM commands list

NPM COMMANDS LIST

Check npm version

npm --version

NPM INSTALL

   # Latest npm installing
       
       npm install npm@latest
       
    # if you installfrom other resource Like git, tarball  
       npm install loadsh@latest 
       npm install <tarball file>
       npm install <tarball url>
       npm install <git remote url>
       npm install gist:<gist-id>
       
    # npm install local
      
       npm install  <package-name>
       npm i  <package-name>    
    
    # npm install local and make an entry in package.json
       npm install <package-name> --save
       
   # npm install globally syntax
      
       npm install --g <package-name>
       npm i  -g <package-name>

   # If you want to install a specific version of a package use: 
       
       npm install <package-name>@<version>
   
   # install a version which matches "version >= 4.10.1" and "version < 4.11.1" 
       
       npm install loadsh@”>= 4.10.1  <4.11.1”
   

   # packages available on GitHub 
  
       npm install <username>/<repository>
  
   # npm install dependencies
       npm install –save <name>
       npm install –S <name>
       npm i –S < name>
   
   # Install dependencies for development purposes 
       $ npm install –save-dev <package-name>


NPM UNINSTALL

       npm uninstall <package-name>
       npm remove <package-name>
       npm rm <package-name>
       npm r <package-name>
       npm unlink <package-name>
       npm un <package-name>
       
    # Global Package Uninstall
    
       npm uninstall  -g <package-name>

   # if you would like to remove the package from package.json as part of uninstallation
    
       npm uninstall  --save <package-name>
       npm uninstall –S <package-name>
    
    # For a development dependency, use the --save-dev flag (shorthand: -D): 
         
       npm uninstall –save-dev <package-name>
       npm uninstall –S <package-name>

NPM INIT

    # If you want ask for configuration then use:
	   npm init	
    # Default configuration in package.json
        npm init –yes
        npm init –y
4.	Packages List
        npm list
        npm list --json
        npm list --dev
        npm list --development
        npm list --prod
        npm list --production
        npm list --global

    json - Shows information in json format
    long - Shows extended information
    parseable - Shows parseable list instead of tree
    global - Shows globally installed packages
    depth - Maximum display depth of dependency tree
    dev/development - Shows devDependencies
    prod/production - Shows dependencies 

NPM UPDATE

   # update all packages
       npm update
   # update a specific package:
       npm update <package-name>
   # In case you also want to lock the updated version in package.json:
       npm update <package-name> --save

NPM cache

    # cache list
        npm cache ls
    # cache clean
        npm cache clean -f

NPM Remove from node_modules folder

    # Remove duplicate packages from node_modules folder
        npm dedupe
    # Remove unused packages from mode_modules folder
        npm prune
        npm prune --production

Lockdown package versions for production

        npm shrinkwrap
    # Also include DevDepdencies
        npm shrinkwrap --dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment