Web Development Tutorial

Node.js Commands: Complete CLI, npm And REPL Command Reference (2026-27)

By Pramod Behera  ·  Updated: July 2026  ·  17 min read
✅ In this Web Technologies Tutorial - Node.js Commands: The Complete CLI, npm And REPL Reference

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

  1. Why Learn Node.js Commands
  2. Core node CLI Commands
  3. Useful node Command-Line Flags
  4. Everyday npm Commands
  5. Understanding npx
  6. package.json Scripts And Custom Commands
  7. Node.js REPL Commands
  8. Debugging And Inspecting Commands
  9. Global vs. Local Installs
  10. Node Version Manager (nvm) Commands
  11. Common Command Mistakes
  12. Command Cheat Sheet
  13. Quick Reference Table
  14. Try It Yourself: Code Playground
  15. Practice Quiz
  16. 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:

🟢
node CLI
Runs your JavaScript files and reports information about the runtime itself.
📦
npm
Installs, removes, and manages the packages your project depends on.
⚡
npx
Runs a package's command directly, without a permanent install.
⌨️
REPL
Interactive shortcuts available once you're inside the node prompt.
🐞
Debugging
Flags that attach a debugger or surface extra information while running.
🔀
nvm
Switches between multiple installed Node.js versions on one machine.

✅ Core node CLI Commands

These are the commands you'll type most often, straight after opening a terminal in your project folder.

CommandWhat It Does
node app.jsRuns the JavaScript file app.js from start to finish.
nodeOpens the interactive REPL prompt with no file involved.
node -v / node --versionPrints the currently active Node.js version.
node -e "code"Executes a short snippet of JavaScript passed directly on the command line.
node --helpLists every available command-line option, with a short description of each.
node --check app.jsParses a file for syntax errors without actually running it.
// Run a snippet without creating a file
node -e "console.log(process.version)"
💡 Tip: 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.

FlagPurpose
--watchAutomatically restarts your script whenever a watched file changes, useful during active development.
--inspectStarts a script with a debugger listening, so tools like Chrome DevTools can attach to it.
--inspect-brkSame as --inspect, but also pauses execution on the very first line until a debugger connects.
--trace-warningsPrints a full stack trace alongside any runtime warning, making the source easier to locate.
--max-old-space-size=SIZERaises the memory limit for Node's garbage-collected heap, useful for memory-hungry scripts.
--env-file=.envLoads 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.

CommandWhat It Does
npm init -yCreates a new package.json file instantly, using sensible default values.
npm installInstalls 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-devInstalls 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 updateUpdates installed packages to the newest version allowed by package.json.
npm outdatedLists installed packages that have a newer version available.
npm listDisplays the installed dependency tree for the current project.
npm run <script>Runs a custom command defined under the scripts section of package.json.
npm auditScans installed dependencies for known security vulnerabilities.
npm ciPerforms 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
⚠️ Watch the flag: Forgetting --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
ℹ️ Naming rule: Only 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 CommandWhat It Does
.helpLists every available REPL dot-command.
.exitCloses the REPL and returns to your regular terminal prompt.
.break / Ctrl+CCancels a multi-line statement that's currently being typed.
.clearResets the current REPL context, clearing any variables defined so far.
.save filename.jsSaves everything typed in the current session to a file.
.load filename.jsLoads and runs a JavaScript file's contents into the current session.
.editorSwitches into a multi-line editing mode, useful for pasting larger blocks of code.
💡 Tip: Pressing the Up Arrow key inside the REPL cycles back through your previous commands, exactly like a regular shell history - handy for re-running or tweaking something you typed a moment ago.

✅ 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 TypeUse 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.

CommandWhat It Does
nvm install 22Downloads and installs a specific major version of Node.js.
nvm use 22Switches the active Node.js version for the current terminal session.
nvm lsLists every Node.js version currently installed on the machine.
nvm alias default 22Sets a version to load automatically whenever a new terminal opens.
nvm currentPrints the Node.js version currently active in this session.
ℹ️ Why this helps: A team where every developer runs the exact same Node.js version, pinned through nvm, avoids an entire category of "it works on my machine" bugs caused by subtle differences between runtime versions.

✅ Common Command Mistakes

✅ Command Cheat Sheet

💡 The commands you'll use almost every single day:

✔️ 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

TermOne-Line Meaning
CLICommand-line interface - the text-based way of controlling node and npm.
FlagAn optional switch, like --watch, that changes a command's behavior.
REPLThe interactive prompt started by running node with no filename.
Global installA package installed once for the whole machine, using the -g flag.
Local installA package installed inside a single project's node_modules folder.
npxRuns a package's command on demand, without a permanent install.
ScriptA custom command defined in package.json and run with npm run.
nvmA 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.


Output will appear here...

✅ 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?

0/5
Your Score - Keep Practising! 🎯

✅ Frequently Asked Questions (FAQ)

What is the difference between npm install and npm ci?
npm install reads package.json, resolves the newest versions allowed by your version ranges, and can update package-lock.json. npm ci instead installs the exact versions already recorded in package-lock.json, deleting node_modules first, which makes it faster and more predictable for automated build environments.
What does npx do differently from npm?
npm installs and manages packages inside a project. npx executes a package's command directly, downloading it temporarily if it is not already installed, which is useful for one-off tools like project generators without permanently adding them to your system.
How do I run a custom script defined in package.json?
Add a name and command pair under the scripts section of package.json, then run it with npm run followed by that name, such as npm run build. The two special script names start and test can be run without the word run, as npm start and npm test.
When should I use npm install -g instead of a local install?
The -g flag installs a package globally on your machine so its command is available in any terminal session, which suits command-line tools you use across many projects. Packages your actual application code depends on should almost always be installed locally instead, without -g.
How can I see which npm packages are installed and which are outdated?
Run npm list to see installed packages and their versions in a tree, and npm outdated to compare your installed versions against the newest versions available in the registry, which helps you decide what to update.
✍️ About the Author - Pramod Behera

Pramod Behera is the founder of LearnToSAP.com and an experienced technology educator. He creates beginner-friendly tutorials spanning SAP modules, web development, and Cyber Security, helping thousands of learners worldwide build practical, job-ready skills.