Node.js Command-Line Options: Controlling Execution and Behavior
Master Node.js execution with this guide to command-line options. Learn how to control various runtime settings, manage script execution, and leverage Node.js's flexibility through command-line arguments for enhanced development and debugging.
Node.js Command Line Options
Node.js offers various command-line options to control its execution and behavior. These options provide flexibility in running scripts and managing runtime settings.
List of Node.js Command Line Options
Index | Option | Description |
---|---|---|
1 | v, --version |
Prints the Node.js version. |
2 | -h, --help |
Prints a list of available command-line options. |
3 | -e, --eval "script" |
Evaluates the provided JavaScript code. Predefined REPL modules are accessible. |
4 | -p, --print "script" |
Similar to --eval , but prints the result to the console. |
5 | -c, --check |
Performs a syntax check on the script without executing it. |
6 | -i, --interactive |
Opens the REPL (Read-Eval-Print Loop) even if input isn't from a terminal. |
7 | -r, --require module |
Preloads the specified module at startup. Uses require() 's module resolution rules. |
8 | --no-deprecation |
Suppresses deprecation warnings. |
9 | --trace-deprecation |
Prints stack traces for deprecation warnings. |
10 | --throw-deprecation |
Throws errors for deprecation warnings. |
11 | --no-warnings |
Suppresses all warnings (including deprecations). |
12 | --trace-warnings |
Prints stack traces for all warnings. |
13 | --trace-sync-io |
Prints stack traces when synchronous I/O is detected after the event loop starts. |
14 | --zero-fill-buffers |
Zero-fills newly allocated buffer instances. |
15 | --track-heap-objects |
Tracks heap object allocations for heap snapshots. |
16 | --prof-process |
Processes V8 profiler output (from the V8 --prof option). |
17 | --v8-options |
Prints available V8 command-line options. |
18 | --tls-cipher-list=list |
Specifies a custom TLS cipher list (requires crypto support). |
19 | --enable-fips |
Enables FIPS-compliant cryptography (requires specific build options). |
20 | --force-fips |
Forces FIPS-compliant cryptography (cannot be disabled in code). |
21 | --icu-data-dir=file |
Specifies the ICU data load path. |
Examples
Here are some example usages:
- Show Node.js version:
node -v
ornode --version
- Get help:
node -h
ornode --help
- Evaluate a script (without printing):
node -e "console.log('Hello');"
- Evaluate and print:
node -p "1+1"
- Open REPL:
node -i
ornode --interactive