Introduction
Node is an open-source, cross-platform JavaScript runtime environment build on Google’s V8 engine. It was created by Ryan Dahl in 2009 to allow for server-side scripting in JavaScript.
ECMAScript Support
Node supports most of the features of ECMAScript 2015 (ES6). However, Node dopated the CommonJS module approach before ES6 modules were proposed, and as a result uses CommonJS modules by default. To use ES6 modules instead, you must either:
- Add
"type":"module"to your package.json file, or - Use the .mjs extension for your files, instead of .js
Examples in this text will use CommonJS modules, but feel free to switch to ES6 modules if you prefer.
You can learn more about Node’s ES6 support here.
Differences between Browser JavaScript and Node
While JavaScript in the browser has been deliberately sandboxed and is only allowed to interact with the current document and the Internet, Node can interact with the file system and operating system of the hosting computer. Also, because Node is not hosted in a browser, it has no Document Object Model (DOM), and no document or window global variables. To reflect this, the global namespace for Node is global instead of window.
Info
Node can be downloaded for Windows, Linux, and MacOS at https://nodejs.org/en/. Documentation for Node is found at https://nodejs.org/en/docs/. On many Linux and Mac systems, multiple versions of Node can be installed and managed using Node Version Manager (nvm). Using nvm may be preferred on those systems since most package repositories include older and outdated versions of Node.
