Node.JS

Node.js

Node.js is a cross-platform, open-source JavaScript runtime environment that can run on Windows, Linux, Unix, macOS, and more. Node.js runs on the V8 JavaScript 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. The ability to run JavaScript code on the server is often used to generate dynamic web page content before the page is sent to the user's web browser. Consequently, Node.js represents a "JavaScript everywhere" paradigm, unifying web-application development around a single programming language, as opposed to using different languages for the server- versus client-side programming.

Node.js has an event-driven architecture capable of asynchronous I/O. These design choices aim to optimize throughput and scalability in web applications with many input/output operations, as well as for real-time Web applications (e.g., real-time communication programs and browser games).

The Node.js distributed development project was previously governed by the Node.js Foundation, and has now merged with the JS Foundation to form the OpenJS Foundation. OpenJS Foundation is facilitated by the Linux Foundation's Collaborative Projects program.

See Node.js on Wikipedia.

Getting started

The Pro Linux Container of Brap is pre-configured for Node.js.

Hello, World! in Command-Line Interface

Here is a Hello, World! application in JavaScript file hello-world.js:

console.log("Hello, World!");

To run the Hello, World! application in the Command-Line Interface (CLI) via Node.js, run:

node hello-world.js

Hello, World! in a web browser

Here is Hello, World! application in JavaScript, via Node.js, that you can access in a web browser hello-world-web.js:

var http = require("http");

http.createServer(function (req, res) {
  res.writeHead(200, {"Content-Type": "text/html"});
  res.end("Hello World!");
}).listen(3000);

To serve the application, run:

node hello-world-web.js

Hello, World! in Node.js

Screenshot: Hello, World! in Node.js running in the web browser

Manage Node.js versions

The Pro Linux Container of Brap is pre-configured with Node Version Manager (NVM). With NVM, you can easily install and run multiple versions of Node.js.

To see which version of Node.js is used by the CLI, run:

node -v

To list the available versions of Node.js, run:

nvm list-remote

To install a version of Node.js, run:

nvm install v20.10.0

To list the versions you have installed, run:

nvm list

To change the version of Node.js used by the CLI, run:

nvm use v12.0.0

Node.js in VS Code terminal and web browser

Screenshot: Node.js in VS Code terminal and web browser

Node Version Manager in VS Code terminal

Screenshot: Node Version Manager (NVM) in VS Code terminal

Keywords

  • node.js
  • node
  • node version manager
  • nvm
  • js
  • javascript
  • web
  • framework
  • backend

Back to top