Basic Setup

Command Description
npm init Launch an interactive prompt to create a package.json file
npm init -y Generate a package.json with default settings
node -v Display the installed Node.js version
npm -v Display the installed npm version

Dependency Management

Command Description
npm install <package> Install a package and add it to dependencies
npm install -g <package> Install a package globally (system-wide)
npm install <package> --save-dev or npm install <package> -D Install a package and add it to devDependencies
npm ci Clean install based on package-lock.json—deletes node_modules, installs exact locked versions; ideal for CI/CD pipelines
npm install Install all dependencies listed in package.json
npm uninstall <package> Remove a package and update package.json
npm update <package> Update an installed package to the latest version within the version range specified in package.json
npm update Update all installed packages to the latest versions satisfying the version ranges specified in package.json
npm outdated List all installed packages that have newer versions available than those currently installed

npm Scripts & Binaries

Command Description
npm run <script> Execute a script defined in package.json
npm start Run the start script (shorthand for npm run start)
npm test Run the test script (shorthand for npm run test)
npx <package> [args] Run a binary from a package, downloading it temporarily if not installed

Node.js Core CLI Options

Command Description
node <file.js> Run a Node.js script in the terminal
node --help Show all available Node.js command-line options
node --watch server.js Run server.js and automatically restart the process when changes are detected in the file itself or in any of its dependencies (imported modules).
node --env-file=.env app.js Load environment variables from .env, then execute app.js