With the wide repository of dependencies in Node.js, any type of application can create either the front-end or back-end. Still, sometimes it is required to interact with the command line.
Not only this, there are various CL options provided by Node.js which are handy in performing small operations. Let’s see them one by one with examples.
Before going future make sure that you have node installed on your pc. Here’s how you can install, set up, and run your first nodeJS app.
Different Types of Node Command Line options
Let’s type the above syntax in the terminal and then type expressions with an operator and operands and press enter to get the result.
2. Printing Command Line Options
Node CL provides an option to print all the command line options in the terminal.
3. Syntax Error Checker
We have a file app.js in which we have made a syntax error to check whether this Node Cl option is able to detect it or not.
4. Execute and Print the Result
It is a way to execute the statement and print the result in the terminal.
node -p "statement"
node -p "2*2"
Here we are supposed to get the value 4 as a result of 2 * 2.
5. Execute and Print the Error
It is a way to execute a statement and print the error it if occurs otherwise it doesn’t print anything.
node -e "statement"
node -e "1 + q"
Here we are typing a statement with a reference error.
Node CL provides a preloader that is used to execute a file before any other file.
node -r priority-file other-file
where the priority-file is the file you want to execute first before the other-file.
7. List of dependency
Node CL provides an option to print all the dependencies used inside a project.
8. Initialize NPM
A standard option that Node Command Line provides is the initialization of NPM which is further used to install dependencies inside the project.
The dependency can be installed by using the following command.
npm install dependency-name
Where dependency-name is the dependency you want to install inside the application.
npm install express
9. V8 CL Options
This option prints v8 command line options.