By default, the node.js comes with a variety of command line (CLI) options and these command-line options will provide multiple debugging and runtime options to execute the scripts in different ways.
The node.js has provided plenty of command-line options, in that the following are the some commonly used command-line options while building node.js applications.
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.
If you observe above result, we used a node -v
and npm -v
commands to get the version details installed in our machine.
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.
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 the following example.
If you observe the above result, we tried to declare a variable (s) in the wrong manner that’s the reason we got a syntax error.
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.
If you observe above result, the node -e
command has evaluated the given expression but the result is printed in the node command line.
By using <module> -p
command, we can evaluate and print the expression result in node.js. It same as <module> -e
command but the 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.
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.
To know more about node.js command-line options, refer https://nodejs.org/api/cli.html URL.