{"id":2892,"date":"2019-09-20T16:37:00","date_gmt":"2019-09-20T21:37:00","guid":{"rendered":"http:\/\/bluegalaxy.info\/codewalk\/?p=2892"},"modified":"2019-09-20T16:37:02","modified_gmt":"2019-09-20T21:37:02","slug":"node-js-how-to-write-node-js-code-locally-and-test-using-the-command-line","status":"publish","type":"post","link":"https:\/\/bluegalaxy.info\/codewalk\/2019\/09\/20\/node-js-how-to-write-node-js-code-locally-and-test-using-the-command-line\/","title":{"rendered":"Node.js: How to write node.js code locally and test using the command line"},"content":{"rendered":"\n<p>The first thing we want to do when getting ready to code in node.js is make sure that <code>Node<\/code> and <code>NPM<\/code> are installed on our machine. Start by opening a command window and type the command <code>node -v<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/09\/image.png\" alt=\"\" class=\"wp-image-2894\" width=\"439\" height=\"166\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/09\/image.png 585w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/09\/image-300x113.png 300w\" sizes=\"auto, (max-width: 439px) 100vw, 439px\" \/><\/figure>\n\n\n\n<p>Then check to confirm that NPM is installed also using the command <code>npm -v<\/code>:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/09\/image-1.png\" alt=\"\" class=\"wp-image-2895\" width=\"188\" height=\"43\"\/><\/figure>\n\n\n\n<p>Once that is confirmed, create a new node.js file called hello.js and add this single line of JavaScript code to test whether the script is running:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">console.log(\"Hello world.\")<\/pre>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/09\/image-2-1024x240.png\" alt=\"\" class=\"wp-image-2897\" width=\"709\" height=\"165\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/09\/image-2-1024x240.png 1024w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/09\/image-2-300x70.png 300w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/09\/image-2-768x180.png 768w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/09\/image-2.png 1057w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><figcaption>I created this file in Atom<\/figcaption><\/figure>\n\n\n\n<p>Now once that file is saved, try running it from the command line with the command <code>node hello.js<\/code>. Note: Don&#8217;t forget to cd to the folder that the file was saved in.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/09\/image-3.png\" alt=\"\" class=\"wp-image-2899\" width=\"416\" height=\"111\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/09\/image-3.png 603w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2019\/09\/image-3-300x81.png 300w\" sizes=\"auto, (max-width: 416px) 100vw, 416px\" \/><\/figure>\n\n\n\n<p>If you see the words &#8220;Hello world.&#8221; on the next line, it confirms that you have successfully created and run a node.js script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The first thing we want to do when getting ready to code in node.js is make sure that Node and NPM are installed on our machine. Start by opening a command window and type the command node -v. Then check to confirm that NPM is installed also using the command npm -v: Once that is &hellip; <a href=\"https:\/\/bluegalaxy.info\/codewalk\/2019\/09\/20\/node-js-how-to-write-node-js-code-locally-and-test-using-the-command-line\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Node.js: How to write node.js code locally and test using the command line<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44,205],"tags":[121,45,58],"class_list":["post-2892","post","type-post","status-publish","format-standard","hentry","category-javascript-language","category-node-js","tag-atom","tag-javascript","tag-node-js"],"_links":{"self":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/2892","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/comments?post=2892"}],"version-history":[{"count":6,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/2892\/revisions"}],"predecessor-version":[{"id":2902,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/2892\/revisions\/2902"}],"wp:attachment":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/media?parent=2892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/categories?post=2892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/tags?post=2892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}