{"id":1500,"date":"2016-06-09T21:08:28","date_gmt":"2016-06-10T02:08:28","guid":{"rendered":"http:\/\/osric.com\/chris\/accidental-developer\/?p=1500"},"modified":"2016-06-09T21:08:28","modified_gmt":"2016-06-10T02:08:28","slug":"node-js-error-console-is-undefined","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2016\/06\/node-js-error-console-is-undefined\/","title":{"rendered":"Node.js &#8211; Error &#8216;console&#8217; is undefined"},"content":{"rendered":"<p>I just installed Node.js on a new system and wanted to make sure it worked. I tested it with a simple <em>hello world<\/em> script.<\/p>\n<p><strong>Contents of the node.js file<\/strong><br \/>\n<code>console.log(\"Hello node\");<\/code><\/p>\n<p>Then I attempted to run it:<br \/>\n<code>C:\\&gt;node node.js<\/code><\/p>\n<p>Which produced the following error:<br \/>\n<code>Script: C:\\node.js<br \/>\nLine: 1<br \/>\nChar: 1<br \/>\nError: 'console' is undefined<br \/>\nCode: 800A1391<br \/>\nSource: Microsoft JScript runtime error<\/code><\/p>\n<p>Weird. And <em>Microsoft JScript runtime?<\/em> Very weird.<\/p>\n<p>Turns out, Windows is trying to run the Javascript, <code>node.js<\/code>, not via Node.js but natively in Windows.<\/p>\n<p>If I rename the file <code>hellonode.js<\/code> I can reproduce the same error:<br \/>\n<code>C:\\&gt;hellonode<\/code><\/p>\n<p>Or I can run the intended file via Node.js:<br \/>\n<code>C:\\&gt;node hellonode.js<br \/>\nHello node<\/code><\/p>\n<p>I did not realize that the Windows command prompt could\/would execute Javascript files natively.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just installed Node.js on a new system and wanted to make sure it worked. I tested it with a simple hello world script. Contents of the node.js file console.log(&#8220;Hello node&#8221;); Then I attempted to run it: C:\\&gt;node node.js Which produced the following error: Script: C:\\node.js Line: 1 Char: 1 Error: &#8216;console&#8217; is undefined Code: &hellip; <a href=\"https:\/\/osric.com\/chris\/accidental-developer\/2016\/06\/node-js-error-console-is-undefined\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Node.js &#8211; Error &#8216;console&#8217; is undefined<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[403],"class_list":["post-1500","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-node-js"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=1500"}],"version-history":[{"count":3,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1500\/revisions"}],"predecessor-version":[{"id":1504,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1500\/revisions\/1504"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=1500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=1500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=1500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}