Node.js Commands: Complete CLI, npm And REPL Command Reference (2026-27)
Today we are discuss topic- Node.js Commands Once you have followed our Node.js Get Started guide and installed Node.js, the next hurdle is remembering which command does what. This tutorial collect every command you will actually reach for in day-to-day work: the node command-line interface and its most useful flags, the npm commands that install and manage packages, npx for running one-off tools, custom scripts inside
package.json, shortcuts available inside the interactive REPL, debugging flags, and the version-switching commands used by nvm. Keep this page bookmarked as a cheat sheet, and finish with the quiz and FAQ to check what's jammed.
📋 Table of Contents
- Why Learn Node.js Commands
- Core node CLI Commands
- Useful node Command-Line Flags
- Everyday npm Commands
- Understanding npx
- package.json Scripts And Custom Commands
- Node.js REPL Commands
- Debugging And Inspecting Commands
- Global vs. Local Installs
- Node Version Manager (nvm) Commands
- Common Command Mistakes
- Command Cheat Sheet
- Quick Reference Table
- Try It Yourself: Code Playground
- Practice Quiz
- Frequently Asked Questions (FAQ)
✅ Why Learn Node.js Commands
Nearly all Node.js work happens in a terminal window, not in a graphical menu. Whether you are running a script, installing a package, checking a version number, or starting a debugger, you'll almost always type a command to do it. Knowing the right command instantly - instead of searching for it every time - is one of the fastest ways to feel comfortable and productive as a Node.js developer.
Broadly speaking, Node.js commands fall into a small number of families:
✅ Core node CLI Commands
These are the commands you'll type most often, straight after opening a terminal in your project folder.
| Command | What It Does |
|---|---|
| node app.js | Runs the JavaScript file app.js from start to finish. |
| node | Opens the interactive REPL prompt with no file involved. |
| node -v / node --version | Prints the currently active Node.js version. |
| node -e "code" | Executes a short snippet of JavaScript passed directly on the command line. |
| node --help | Lists every available command-line option, with a short description of each. |
| node --check app.js | Parses a file for syntax errors without actually running it. |
// Run a snippet without creating a file
node -e "console.log(process.version)"
node -e is handy for a quick one-line check - like confirming a package's version or testing a small expression - without opening a text editor at all.
✅ Useful node Command-Line Flags
Flags change how the node command behaves when it runs a file. You'll reach for a handful of these regularly once you move past "Hello World" scripts.
| Flag | Purpose |
|---|---|
| --watch | Automatically restarts your script whenever a watched file changes, useful during active development. |
| --inspect | Starts a script with a debugger listening, so tools like Chrome DevTools can attach to it. |
| --inspect-brk | Same as --inspect, but also pauses execution on the very first line until a debugger connects. |
| --trace-warnings | Prints a full stack trace alongside any runtime warning, making the source easier to locate. |
| --max-old-space-size=SIZE | Raises the memory limit for Node's garbage-collected heap, useful for memory-hungry scripts. |
| --env-file=.env | Loads environment variables from a specified file before your script starts running. |
// Restart automatically whenever app.js changes
node --watch app.js
✅ Everyday npm Commands
npm is installed automatically with Node.js and handles everything related to packages - installing them, removing them, updating them, and running the scripts defined in your project.
| Command | What It Does |
|---|---|
| npm init -y | Creates a new package.json file instantly, using sensible default values. |
| npm install | Installs every dependency listed in the current project's package.json. |
| npm install <package> | Installs a specific package and adds it as a regular dependency. |
| npm install <package> --save-dev | Installs a package as a development-only dependency, such as a test runner. |
| npm install -g <package> | Installs a package globally, so its command is available from any project. |
| npm uninstall <package> | Removes a package and deletes its entry from package.json. |
| npm update | Updates installed packages to the newest version allowed by package.json. |
| npm outdated | Lists installed packages that have a newer version available. |
| npm list | Displays the installed dependency tree for the current project. |
| npm run <script> | Runs a custom command defined under the scripts section of package.json. |
| npm audit | Scans installed dependencies for known security vulnerabilities. |
| npm ci | Performs a clean, exact install based strictly on package-lock.json. |
// Add Express as a normal dependency
npm install express
// Add a testing tool only for development
npm install jest --save-dev
--save-dev for tools that are only needed during development - like linters or test runners - means they get bundled with your regular dependencies, which is not wrong, but blurs the distinction package.json is meant to capture.
✅ Understanding npx
npx ships alongside npm and solves a specific problem: running a package's command without permanently installing it. If the package is already installed locally, npx uses that copy; otherwise, it downloads a temporary copy, runs it once, and discards it afterward.
// Run a project generator once, without installing it globally
npx create-react-app my-app
// Run a locally installed tool directly, without a package.json script
npx eslint .
This matters because installing every command-line tool globally clutters your machine with packages you may only ever run once, and can lead to different developers on a team silently using different tool versions. npx sidesteps both problems by fetching whatever version is appropriate at the moment you run it.
✅ package.json Scripts And Custom Commands
Beyond built-in npm commands, you can define your own shortcuts inside the scripts section of package.json. This keeps long or awkward commands consistent across every developer working on a project.
{
"scripts": {
"start": "node server.js",
"dev": "node --watch server.js",
"test": "jest",
"lint": "eslint .",
"build": "webpack --mode production"
}
}
With scripts defined this way, teammates never need to memorize the exact underlying tool or its flags - they just run one of these:
npm start
npm test
npm run dev
npm run lint
npm run build
start and test can be run without the word "run" - every other custom script name needs npm run in front of it, for example npm run build rather than npm build.
✅ Node.js REPL Commands
Once you're inside the interactive REPL (started by typing node with no filename), a separate set of dot-commands becomes available. These aren't JavaScript - they're special instructions understood only by the REPL itself.
| REPL Command | What It Does |
|---|---|
| .help | Lists every available REPL dot-command. |
| .exit | Closes the REPL and returns to your regular terminal prompt. |
| .break / Ctrl+C | Cancels a multi-line statement that's currently being typed. |
| .clear | Resets the current REPL context, clearing any variables defined so far. |
| .save filename.js | Saves everything typed in the current session to a file. |
| .load filename.js | Loads and runs a JavaScript file's contents into the current session. |
| .editor | Switches into a multi-line editing mode, useful for pasting larger blocks of code. |
✅ Debugging And Inspecting Commands
When a script misbehaves, Node.js offers built-in ways to inspect what's happening, without installing any extra tooling.
🐞 node --inspect app.js
Starts your script with a debugging port open, so you can attach Chrome DevTools by visiting chrome://inspect in the browser.
⏸️ node --inspect-brk app.js
Identical to --inspect, but execution pauses on the very first line, giving you time to set breakpoints before anything runs.
📋 node --trace-warnings app.js
Shows a full stack trace for any process warning, instead of just a one-line summary, making the origin far easier to trace.
// Start debugging and pause on line 1
node --inspect-brk server.js
✅ Global vs. Local Installs
Deciding whether to add -g to an npm install command trips up a lot of newcomers. The rule of thumb is straightforward:
| Install Type | Use It For |
|---|---|
| Local (default, no -g) | Anything your application code actually imports and depends on to run, such as Express or Axios. |
| Global (-g flag) | Stand-alone command-line tools you want available everywhere, such as a scaffolding generator you use across many unrelated projects. |
// See every package installed globally on this machine
npm list -g --depth=0
When in doubt, prefer a local install combined with a package.json script or an npx call - it keeps your project self-contained and reproducible on any machine, which a global install cannot guarantee.
✅ Node Version Manager (nvm) Commands
Different projects sometimes require different Node.js versions. Rather than reinstalling Node.js repeatedly, most developers install a version manager such as nvm, which lets multiple versions live side by side.
| Command | What It Does |
|---|---|
| nvm install 22 | Downloads and installs a specific major version of Node.js. |
| nvm use 22 | Switches the active Node.js version for the current terminal session. |
| nvm ls | Lists every Node.js version currently installed on the machine. |
| nvm alias default 22 | Sets a version to load automatically whenever a new terminal opens. |
| nvm current | Prints the Node.js version currently active in this session. |
✅ Common Command Mistakes
- Running npm install with no arguments when you actually meant to add a new package - remember to name the package after the command.
- Using -g out of habit for packages that should really be project dependencies, which then breaks for teammates who never installed that global tool.
- Typing npm build instead of npm run build for any custom script name other than start or test.
- Forgetting --save-dev for development-only tools, mixing them in with runtime dependencies.
- Leaving --inspect-brk on in production, which pauses the process on startup and can look like the app has frozen.
- Ignoring npm audit warnings for months at a time instead of reviewing and patching them regularly.
✅ Command Cheat Sheet
✔️
node app.js - run a file✔️
node -v - check the Node.js version✔️
npm init -y - start a new project✔️
npm install <package> - add a dependency✔️
npm run <script> - run a custom script✔️
npx <tool> - run a tool without installing it permanently✔️
node --watch app.js - auto-restart while developing✔️
npm audit - check for known vulnerabilities
✅ Node.js Commands - Quick Reference Table
| Term | One-Line Meaning |
|---|---|
| CLI | Command-line interface - the text-based way of controlling node and npm. |
| Flag | An optional switch, like --watch, that changes a command's behavior. |
| REPL | The interactive prompt started by running node with no filename. |
| Global install | A package installed once for the whole machine, using the -g flag. |
| Local install | A package installed inside a single project's node_modules folder. |
| npx | Runs a package's command on demand, without a permanent install. |
| Script | A custom command defined in package.json and run with npm run. |
| nvm | A tool for installing and switching between Node.js versions. |
✅ Try It Yourself: Code Game Playground
Edit the JavaScript below and click "Run" to see simulated console output. This demonstrates how you'd inspect values from inside a real Node.js script, run identically with node yourfile.js.
✅ Practice - Yes / No Quiz
1. Does npm install read the dependency list from package.json?
2. Does npx require a package to already be installed globally before it can run it?
3. Is node -v the same as node --version?
4. Should regular application dependencies normally be installed with the -g flag?
5. Does a custom script name (other than start or test) require npm run in front of it?