Introduction
Executing your JavaScript Code outside a web browser, you need to install Node.js.
Definition
Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser. Node.js lets developers use JavaScript to write command line tools and for server-side scripting—running scripts server-side to produce dynamic web page content before the page is sent to the user’s web browser. Consequently, Node.js represents a “JavaScript everywhere” paradigm,[6] unifying web-application development around a single programming language, rather than different languages for server-side and client-side scripts.
Learn more: https://en.wikipedia.org/wiki/Node.js
Ryan Dahl in 2009 decided “it would be great to run it outside the browsers” before Node.js we only had that runtime that Web APIs and Call back Queue in event loop all browsers based.
Install Node.js
Click the Link and Download pkg
https://nodejs.org/en/download/
It is always better to check the version and location of Node.js which you installed.
$ node -v
v12.18.3
$ which node
/usr/local/bin/node
npm (originally short for Node Package Manager)[4] is a package manager for the JavaScript programming language maintained by npm, Inc.
$ npm -v
6.14.6
$ which npm
/usr/local/bin/npm
with npm config list
command, you can check the basic configuration of Node.js on your computer.
$ npm config list
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.14.6 node/v12.18.3 darwin x64"
; node bin location = /usr/local/bin/node
; HOME = /Users/jayjo
; "npm config ls -l" to show all defaults.
Now, you are able to print Hello World with JavaScript code
Create hello.js file
// If you are using mac or linux
$ touch hello.js
In hello.js file
console.log("Hello World");
$ node hello.js
# Hello World