Node.js Command Line Options

By default, the node.js comes with a variety of command line (CLI) options and these command line options will provide a multiple debugging and runtime options to execute the scripts in different ways.

The node.js has provided a plenty of command line options, in that following are the some of commonly used command line options while building a node.js applications.

Get Version information in Node.js

By using <module> -v or <module> --version commands, we can easily get the version of node.js modules which we installed in our machine.

 

Following is the example of getting the node and npm version details in node.js command prompt.

 

Node.js Get Version Information Command Example Result

 

If you observe above result, we used a node -v and npm -v commands to get the version details installed in our machine.

Help Options in Node.js

By using <module> -h or <module> --help commands, we can get the help information available for particular modules which we installed in our machine.

 

Following is the example of getting the node help option details in node.js command prompt.

 

Node.js Help Command Line Option Example Result

Check Expression Syntax in Node.js

By using <module> -c command, we can validate whether the given expression syntax is correct or not. To use this command, first we need to enter <module> -c command and then click on Enter, after that we need to enter the expression which we want to validate like as shown in following example.

 

Node.js Check Expression Command Line Option Example Result

 

If you observe above result, we tried to declare a variable (s) in wrong manner that’s the reason we got a syntax error.

Evaluate the Expression in Node.js

The <module> -e or <module> --eval command will evaluate the given expression but it doesn’t print the evaluated result.

 

Following is the example of evaluating the expression using node -e command in node.js.

 

Node.js Evaluate Expression Command Line Option Example Result

 

If you observe above result, the node -e command has evaluated the given expression but the result is printed in node command line.

Evaluate & Print Expression Result in Node.js

By using <module> -p command, we can evaluate and print the expression result in node.js. It same as <module> -e command but only difference is it will print the expression result in node shell.

 

Following is the example of evaluating the expression using node -p command in node.js.

 

Node.js Print Expression Command Line Option Example Result

V8 Options in Node.js

By using <mode> --v8-options command, we can see all the available v8 command line options.

 

Following is the example of getting a v8 options using node --v8-options command in node.js.

 

Node.js V8 Command Line Option Example Result

 

To know more about node.js command line options, refer https://nodejs.org/api/cli.html URL.