What is Node.js?

In short
Node.js is an open-source, cross-platform runtime that lets you run JavaScript outside the web browser. It is commonly used to build servers, command-line tools and many other kinds of projects. Its main strength is handling many connections at once without creating a new thread for each one.
What Node.js does
Normally, JavaScript runs inside a web browser. Node.js takes the same JavaScript engine, called V8, and runs it on your own computer or server. V8 is the engine at the heart of Google Chrome. Because Node.js runs outside the browser, you can write programs that read files, talk to a network or serve web pages.
Node.js is open source, which means its source code is public and anyone can read or contribute to it. It works on several operating systems, so the same program can usually run on different machines.
How it works
A Node.js app runs in a single process. It does not create a new thread for every request that comes in. A thread is a separate path of work inside a program, and making many of them can be costly and error-prone.
Instead, Node.js relies on asynchronous input and output, often written as I/O. When your code asks for something slow, such as data from a database, a file from the disk or a response from the network, Node.js does not sit and wait. It keeps going with other work and comes back to your code when the answer arrives. Most of the libraries in Node.js are written this way, so blocking the program is the exception rather than the norm.
The result is that one Node.js server can handle thousands of concurrent connections. Concurrent means many at the same time. You do not have to manage a pool of threads yourself, which saves you from a common source of bugs.
Why developers choose it
Many frontend developers already write JavaScript for the browser. With Node.js they can write server-side code in the same language, so they do not need to learn a completely different one. Teams can share knowledge and sometimes even code between the browser and the server.
Node.js also lets you pick the version of the ECMAScript standard you want to use. ECMAScript is the official specification behind JavaScript. You do not have to wait for every user to update a browser. You choose the Node.js version that suits your project, and you can turn on specific experimental features with flags when you start the program.
A simple example
The classic first program is a small web server that replies with "Hello World". Here is a version that uses CommonJS modules, which rely on require():
const { createServer } = require('node:http');
const hostname = '127.0.0.1';
const port = 3000;
const server = createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(Server running at http://${hostname}:${port}/);
});
Save this as server.js and run node server.js in your terminal. Then open http://127.0.0.1:3000/ in a browser. The code loads the built-in http module, creates a server and tells it to listen on a port. Each time a request arrives, the function you pass in receives two objects: the request, which holds the incoming details, and the response, which you use to send data back. The code sets a status code of 200, which means success, sets a header describing the content type, and ends the response with the text.
If your project uses ECMAScript modules with import, the same server can be written with import syntax. Save that version as server.mjs or use a project setting that enables modules. Which style you use depends on your project's configuration.
Getting started
To try Node.js, download it from the official website and check the installation by running node in your terminal. The official introduction walks through the basics in more detail, and you can read it at the link above. Once you are comfortable with the server example, you can explore the standard library and build small tools of your own.
FAQ
Is Node.js a programming language?
No. Node.js is a runtime that runs JavaScript code outside the browser. The language itself is JavaScript, and Node.js provides the environment and built-in libraries that let that code do things like serve web pages.
Do I need to know JavaScript before using Node.js?
Yes, a basic understanding of JavaScript helps a lot, because you write your Node.js programs in that language. If you already know it from the browser, the move to Node.js is usually smooth.
Why does Node.js handle many connections without many threads?
It uses asynchronous input and output, so it does not wait idly for slow operations like network or disk access. It resumes work when the result comes back, which lets one process serve many connections at once.
What is the difference between require() and import in Node.js?
They are two module systems for loading code from other files. require() belongs to CommonJS, while import belongs to ECMAScript modules. Your project's configuration decides which one you should use.
Sources
This page is based on the official documentation below. Read it for full detail.
Node.js — official documentation ↗Node.js in the news
Mock Service Worker 3.0 drops CommonJS-era builds, intercepts at the socket level and adds GraphQL subscriptions
Mock Service Worker has released version 3.0 as an ESM-only package, with a new Node.js interception layer that works at the TCP and TLS level and support for GraphQL subscriptions. Teams upgrading from v2 face breaking changes.
