
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
Node.js - Command Line Options
The Node.js provides the various command-line options, which allow the user to configure and control the runtime environment effectively. These options enables the debugging, performance tuning and customization of the execution environment. In this tutorial we are going to going to explore the commonly used Node.js command-line options and their functionalities.
Running a Node.js ScriptsFor executing the Node.js script, use the following syntax:
node filename.js
Commonly used Node.js Command Lines
Let's look at the some of the commonly used command lines.
--help
It is used to display the list of available command-line options and their descriptions. It is used for referencing the available flags and their functionality.
node --help
When we execute, this command prints the detailed list of all the command-line options supported by the Node.js runtime, including the debugging options, execution flags and memory related settings. It serves as a built-in manual for understanding how to configure the Node.js via the command line.
--version
It is used to display the installed Node.js version, which is used for verifying the current runtime environment. Keeping the track of the Node.js version is important when working with the different projects that may requires the specific versions.
node --versionor
node -v
The output will be similar to:
v22.13.1
-e or --eval
It executes the JavaScript code directly from the command line without creating a separate file. It is useful for testing small snippets of code, performing calculations or debugging simple logic without writing a full script file.
node -e "console.log('Welcome to, Tutorialspoint.!');"Output
When we execute, it will generate the following output.
Welcome to, Tutorialspoint.!
We can also use this option to execute the multi-line JavaScript by wrapping the code in the quotes and separating the lines with semicolons.
node -e "let x=112; let a=234; console.log(x+a);"Output
346
-p or --print
It evaluates and prints the result of the given JavaScript expression. This option used for quick calculations, debugging and testing expressions without the need of separate script file.
It works similarly to the -e, but automatically prints the output without the need of explicit console.log.
node -p "112 - 321";Output
-209
We can also use this option to print the result of the function calls or object properties.
node -p "Math.sqrt(121)";Output
11
--check or -c
It is used to check the syntax of the JavaScript file without executing it. This option is used for verifying if a script has a valid syntax before running it, helps in find the errors in the early stage.
Let's look at the simple example, where we are going to consider the JavaScript file saved as 'test.js' contains the script as shown below:
test.jsconsole.log("Welcome To, TP.!");Applying --check
node --check test.js
This command will not produce any output, if there are no syntax errors. If there are any errors, it will display the error message and indicate the error line.
For example, if the test.js contains an error:
test.jsconsole.log("Welcome To, TP.!";Applying --check
node --check test.jsOutput
When executed, it will generate an output as shown below:
C:\Users\Lenovo\test.js:1 console.log("Welcome To, TP.!"; ^^^^^^^^^^^^^^^^^^ SyntaxError: missing ) after argument list