Monday, July 29, 2019

What is Node.js Command Line Options ?

There is a wide variety of command line options in Node.js. These options provide multiple ways to execute scripts and other helpful run-time options.
Let's see the list of Node.js command line options:
IndexOptionDescription
1.v, --versionIt is used to print node's version.
2.-h, --helpIt is used to print node command line options.
3.-e, --eval "script"It evaluates the following argument as JavaScript. The modules which are predefined in the REPL can also be used in script.
4.-p, --print "script"It is identical to -e but prints the result.
5.-c, --checkSyntax check the script without executing.
6.-i, --interactiveIt opens the REPL even if stdin does not appear to be a terminal.
7.-r, --require moduleIt is used to preload the specified module at startup. It follows require()'s module resolution rules. Module may be either a path to a file, or a node module name.
8.--no-deprecationSilence deprecation warnings.
9.--trace-deprecationIt is used to print stack traces for deprecations.
10.--throw-deprecationIt throws errors for deprecations.
11.--no-warningsIt silence all process warnings (including deprecations).
12.--trace-warningsIt prints stack traces for process warnings (including deprecations).
13.--trace-sync-ioIt prints a stack trace whenever synchronous i/o is detected after the first turn of the event loop.
14.--zero-fill-buffersAutomatically zero-fills all newly allocated buffer and slowbuffer instances.
15.--track-heap-objectsIt tracks heap object allocations for heap snapshots.
16.--prof-processIt processes V8 profiler output generated using the v8 option --prof.
17.--V8-optionsIt prints V8 command line options.
18.--tls-cipher-list=listIt specifies an alternative default tls cipher list. (requires node.js to be built with crypto support. (default))
19.--enable-fipsIt enables fips-compliant crypto at startup. (requires node.js to be built with ./configure --openssl-fips)
20.--force-fipsIt forces fips-compliant crypto on startup. (cannot be disabled from script code.) (same requirements as --enable-fips)
21.--icu-data-dir=fileIt specifies ICU data load path. (Overrides node_icu_data)

Node.js Command Line Options Examples

To see the version of the running Node:

Open Node.js command prompt and run command node -v or node --version
Node.js Command Line Options 1

For Help:

Use command node ?h or node --help
Node.js Command Line Options 2

To evaluate an argument (but not print result):

Use command node -e, --eval "script"

To evaluate an argument and print result also:

Use command node -p "script"
Node.js Command Line Options 3

To open REPL even if stdin doesn't appear:

Use command node -i, or node --interactive
Node.js Command Line Options 4

No comments:

Post a Comment