{"id":13673,"date":"2022-10-31T19:01:49","date_gmt":"2022-10-31T13:31:49","guid":{"rendered":"https:\/\/codeforgeek.com\/?p=13673"},"modified":"2022-11-09T19:02:18","modified_gmt":"2022-11-09T13:32:18","slug":"nodejs-command-line-options","status":"publish","type":"post","link":"https:\/\/codeforgeek.com\/nodejs-command-line-options\/","title":{"rendered":"NodeJS Command Line Options"},"content":{"rendered":"\n<p>Node.js gives the power to interact with the command line and perform different operations by giving the command line options which can be used for different purposes like running JavaScript code, checking for errors in a particular file or even in a single line, installing dependencies, printing stack traces, etc.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>For example, we want to check for an error in a particular statement of JavaScript, so we have to create a folder then create a file to insert the required code then execute the file, and then it throws the error, but with the help of Node Cl Options, we can do it in a single line of code.<\/p>\n\n\n\n<p>Not only this, there are various CL options provided by Node.js which are handy in performing small operations. Let\u2019s see them one by one with examples.<\/p>\n\n\n\n<p>Before going future make sure that you have node installed on your pc. Here&#8217;s how you can <a href=\"https:\/\/codeforgeek.com\/nodejs-installation-setup-and-hello-world-application\/\">install, set up, and run your first nodeJS app<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Different Types of Node Command Line options<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>REPL<\/strong><\/h3>\n\n\n\n<p>REPL stands for read-eval-print-loop. Node.js provide REPL to run JavaScript directly on the terminal.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nnode\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"646\" height=\"422\" src=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/repl.png\" alt=\"Repl\" class=\"wp-image-13677\" srcset=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/repl.png 646w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/repl-300x196.png 300w\" sizes=\"(max-width: 646px) 100vw, 646px\" \/><\/figure>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>Let\u2019s type the above syntax in the terminal and then type expressions with an operator and operands and press enter to get the result.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"689\" height=\"416\" src=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/repl-example-2.png\" alt=\"Repl Example 2\" class=\"wp-image-13678\" srcset=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/repl-example-2.png 689w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/repl-example-2-300x181.png 300w\" sizes=\"(max-width: 689px) 100vw, 689px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Printing Command Line Options<\/strong><\/h3>\n\n\n\n<p>Node CL provides an option to print all the command line options in the terminal.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nnode --help\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"716\" src=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/all-cl-options-1024x716.png\" alt=\"All Cl Options\" class=\"wp-image-13679\" srcset=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/all-cl-options-1024x716.png 1024w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/all-cl-options-300x210.png 300w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/all-cl-options-768x537.png 768w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/all-cl-options.png 1495w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>Syntax Error Checker<\/strong><\/h3>\n\n\n\n<p>By using Node CL we can check the syntax error of a particular JavaScript file.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nnode -c javascript-file-name\n<\/pre><\/div>\n\n\n<p>where javascript-file-name is the name of the file for which you want to check the error.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"778\" height=\"350\" src=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/syntax-error-1.png\" alt=\"Syntax Error 1\" class=\"wp-image-13687\" srcset=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/syntax-error-1.png 778w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/syntax-error-1-300x135.png 300w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/syntax-error-1-768x346.png 768w\" sizes=\"(max-width: 778px) 100vw, 778px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>Execute and Print the Result<\/strong><\/h3>\n\n\n\n<p>It is a way to execute the statement and print the result in the terminal.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nnode -p &quot;statement&quot;\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nnode -p &quot;2*2&quot;\n<\/pre><\/div>\n\n\n<p>Here we are supposed to get the value 4 as a result of 2 * 2.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"683\" height=\"382\" src=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/p-flag.png\" alt=\"P Flag\" class=\"wp-image-13680\" srcset=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/p-flag.png 683w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/p-flag-300x168.png 300w\" sizes=\"(max-width: 683px) 100vw, 683px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Execute and Print the Error<\/strong><\/h3>\n\n\n\n<p>It is a way to execute a statement and print the error it if occurs otherwise it doesn&#8217;t print anything.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nnode -e &quot;statement&quot;\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nnode -e &quot;1 + q&quot;\n<\/pre><\/div>\n\n\n<p>Here we are typing a statement with a reference error.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"950\" height=\"593\" src=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/e-flag.png\" alt=\"E Flag\" class=\"wp-image-13681\" srcset=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/e-flag.png 950w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/e-flag-300x187.png 300w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/e-flag-768x479.png 768w\" sizes=\"(max-width: 950px) 100vw, 950px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">6. <strong>Preloader<\/strong><\/h3>\n\n\n\n<p>Node CL provides a preloader that is used to execute a file before any other file.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nnode -r priority-file other-file\n<\/pre><\/div>\n\n\n<p>where the priority-file is the file you want to execute first before the other-file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7. <strong>List of dependency<\/strong><\/h3>\n\n\n\n<p>Node CL provides an option to print all the dependencies used inside a project.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nnpm ls\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"1011\" height=\"486\" src=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/npm-ls.png\" alt=\"Npm Ls\" class=\"wp-image-13683\" srcset=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/npm-ls.png 1011w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/npm-ls-300x144.png 300w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/npm-ls-768x369.png 768w\" sizes=\"(max-width: 1011px) 100vw, 1011px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">8. <strong>Initialize NPM<\/strong><\/h3>\n\n\n\n<p>A standard option that Node Command Line provides is the initialization of NPM which is further used to install dependencies inside the project.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nnpm init\n<\/pre><\/div>\n\n\n<p>The dependency can be installed by using the following command.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nnpm install dependency-name\n<\/pre><\/div>\n\n\n<p>Where dependency-name is the dependency you want to install inside the application.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nnpm install express\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"634\" height=\"247\" src=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/npm-install.png\" alt=\"Npm Install\" class=\"wp-image-13685\" srcset=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/npm-install.png 634w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/npm-install-300x117.png 300w\" sizes=\"(max-width: 634px) 100vw, 634px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">9. <strong>V8 CL Options<\/strong><\/h3>\n\n\n\n<p>This option prints v8 command line options.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nnode --v8-options\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"443\" src=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/v8-options-1024x443.png\" alt=\"V8 Options\" class=\"wp-image-13684\" srcset=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/v8-options-1024x443.png 1024w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/v8-options-300x130.png 300w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/v8-options-768x332.png 768w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/v8-options.png 1515w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Summary<\/strong><\/h2>\n\n\n\n<p>The Node CL option is a fast way to execute a file, find errors, and get results for various calculations. We can run JavaScript code directly through it on the terminal. When we are maintaining the server made by Node.js, these options become very important, like getting the stack trace, setting priority to execute a file before others, etc. Hope this article helps you to learn Node Command Line Options.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Reference<\/strong><\/h2>\n\n\n\n<p><a href=\"https:\/\/nodejs.org\/api\/cli.html#options\" target=\"_blank\" rel=\"noopener\">https:\/\/nodejs.org\/api\/cli.html#options<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Node.js gives the power to interact with the command line and perform different operations by giving the command line options which can be used for different purposes like running JavaScript code, checking for errors in a particular file or even in a single line, installing dependencies, printing stack traces, etc. With the wide repository of [&hellip;]<\/p>\n","protected":false},"author":79,"featured_media":13674,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_surecart_dashboard_logo_width":"180px","_surecart_dashboard_show_logo":true,"_surecart_dashboard_navigation_orders":true,"_surecart_dashboard_navigation_invoices":true,"_surecart_dashboard_navigation_subscriptions":true,"_surecart_dashboard_navigation_downloads":true,"_surecart_dashboard_navigation_billing":true,"_surecart_dashboard_navigation_account":true,"_uag_custom_page_level_css":"","footnotes":""},"categories":[14],"tags":[],"class_list":["post-13673","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nodejs"],"blocksy_meta":[],"uagb_featured_image_src":{"full":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/Node.js-command-line-options-thumbnail.png",1200,600,false],"thumbnail":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/Node.js-command-line-options-thumbnail-150x150.png",150,150,true],"medium":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/Node.js-command-line-options-thumbnail-300x150.png",300,150,true],"medium_large":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/Node.js-command-line-options-thumbnail-768x384.png",768,384,true],"large":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/Node.js-command-line-options-thumbnail-1024x512.png",1024,512,true],"1536x1536":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/Node.js-command-line-options-thumbnail.png",1200,600,false],"2048x2048":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2022\/10\/Node.js-command-line-options-thumbnail.png",1200,600,false]},"uagb_author_info":{"display_name":"Aditya Gupta","author_link":"https:\/\/codeforgeek.com\/author\/aditya\/"},"uagb_comment_info":0,"uagb_excerpt":"Node.js gives the power to interact with the command line and perform different operations by giving the command line options which can be used for different purposes like running JavaScript code, checking for errors in a particular file or even in a single line, installing dependencies, printing stack traces, etc. With the wide repository of&hellip;","_links":{"self":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/posts\/13673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/users\/79"}],"replies":[{"embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/comments?post=13673"}],"version-history":[{"count":0,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/posts\/13673\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/media\/13674"}],"wp:attachment":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/media?parent=13673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/categories?post=13673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/tags?post=13673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}