Node.js Command Line Usage

Node.js Command Line Usage
Node.js Command Line Usage CLI (Command Line Interface) that allows you to run JavaScript files, execute commands, manage packages, and interact with the Node.js REPL.
Below are all the important command-line usages.
1. Run a JavaScript File
Example file: app.js
Or with a path:
2. Check Node.js Version
or
3. Use Node.js REPL (Interactive Mode)
Start REPL:
Run JavaScript directly:
Exit REPL:
or:
4. Run Node.js Script with Arguments
Use this:
Example:
Inside app.js:
Output:
5. Run Node.js with Flags
Enable ES Modules
Increase memory limit
Run with tracing
6. Run Node.js Code Without File
-e means evaluate inline code.
7. Watch Mode (Auto Reload) — Node 18+
Automatically reload when file changes:
8. Execute JSON or WASM (Special Cases)
9. Start a Server Directly
10. Node.js Help Command
Shows all available CLI options.
11. Run Node.js Package Scripts (via NPM)
From package.json:
or:
Summary: Important Node CLI Commands
| Task | Command |
|---|---|
| Run JS file | node file.js |
| Interactive REPL | node |
| Evaluate code | node -e "code" |
| Run with watch mode | node --watch file.js |
| Check version | node -v |
| Show help | node --help |
| Pass arguments | node file.js arg1 arg2 |
