buymeasoda RefDocs
  • Overview
  • General
    • Android
    • Apache
    • Fish
    • Git
    • Github
    • Gmail
    • Homebrew
    • iOS
    • iTerm
    • MacOS
    • MacPorts
    • Mamp
    • Media
    • Mercurial
    • MySQL
    • Node
    • npm
    • nvm
    • Obsidian
    • PHP
    • React Native
    • Rust
    • Server
    • Slack
    • Sourcegraph
    • Tools
    • Vim
    • VS Code
    • Yarn
  • Unix
    • Checksum and hash utilities
    • Command line history
    • Command line keyboard shortcuts
    • Compress files and folders
    • Crontab
    • Diff files and folders
    • Disk usage and file sizes
    • Find and search files
    • Firewall configuration
    • Help and manual pages
    • HostName and Local HostName for Mac OSX
    • Navigating the file system
    • Network, domains and routing
    • Run and manage background tasks
    • Secure FTP SFTP and Secure Copy SCP
    • Secure Shell SSH
    • Sync files and folders
    • System and process management
    • System and user information
    • Useful characters
    • Useful commands
    • User, file and group permissions
    • Working with cURL
    • Working with files and directories
    • Working with text
Powered by GitBook
On this page
  • npm
  • Information
  • List
  • Init
  • Install
  • Uninstall
  • Update
  • Scripts
  • Global Packages and Cache
  • Command Aliases
  • Configuration
  • Manage package.json init defaults
  1. General

npm

npm

Information

Show npm version and help

npm -v
npm help

Search for node packages

npm search <package>

Show information for a package

npm info <package>

Show available versions or publish dates for a package

npm view <package> versions --json
npm view <pacakge> time --json

Show location of global modules folder

npm root --global

Open home page or github repo for package

npm home <package>
npm repo <package>

Check if npm requires updating

npm outdated -g npm

List

List installed packages (local / global)

npm list
npm list --global

List only top level global packages

npm list --depth=0
npm list --global --depth=0

Init

Initialize package config in current folder (-y or --yes for default setup)

npm init
npm init --yes

Install

Install all configured package.json dependencies (dev and production)

npm install

Install configured package.json dependencies for specific mode

npm install --dev
npm install --production

Install new local package

npm install <package>
npm install --save <package>

Install new dev (-D), prod (-P), optional (-O) or global (-g) package

npm install --save-dev <package>
npm install --save-prod <package>
npm install --save-optional <package>
npm install --global <package>

Install without saving reference in package.json

npm install --no-save <package>

Install specific version

npm install <package>@<version>

Uninstall

Uninstall package (local, dev, global)

npm uninstall <package>
npm uninstall --save-dev <package>
npm uninstall --global <package>

Remove packages not declared in package.json

npm prune

Update

Update all packages or specific package (local, global)

npm update
npm update <package>
npm update --global
npm update --global <package>

Show outdated packages

npm outdated

Scripts

package.json default script options

npm start
npm stop
npm test

Other scripts require "run"

npm run <script-name>

When executing scripts pre and post versions will automatically run if defined

pre<script-name>
post<script-name>

Global Packages and Cache

Clear the global cache

npm cache clean --force

Command Aliases

  • npm i (npm install)

  • -g (--global)

  • -D (--save-dev)

Configuration

Global configuration file

~/.npmrc

Set npm configuration values for specified keys

npm set <key> <value>

Manage package.json init defaults

Set default init config values

npm config set init-<field> "<value>"
npm set init-<field> "<value>"

Show default init config values

npm config get init-<field>
npm get init-<field>

Delete default init config values

npm config delete init-<field>
PreviousNodeNextnvm

Last updated 3 years ago