Node.js
A workshop that lets JavaScript run outside the browser—directly on your computer or a server—for web backends and handy tools.
On this page
What is Node.js?
Node.js is a JavaScript runtime—think of it as a workshop where JavaScript can run. JavaScript used to live only inside web browsers to make pages interactive; Node.js lets it run directly on your computer or on a server too.
A browser is JavaScript’s first home, and Node.js is its second home. It speaks the exact same language in both places, but each home has different tools: browsers draw pages, while Node.js handles files and runs servers.
JavaScript is the programming language. Node.js is the environment that runs it outside the browser.
How does a Node.js program run?
You write JavaScript code and hand it to Node.js. It can run automatic tasks on your computer or start a server that answers visitors.
Write a code file: create a
.jsor.mjsfile with the steps you want the computer to follow.Run it in the terminal: open your computer’s terminal (the text window for typing commands) and run
node filenameso Node.js executes your file.Use computer and server tools: while running, it can read and write files on disk, connect to databases, and run servers—things a normal web page in a browser is not allowed to do freely.
Stay open for visitors: if you wrote a web backend, it stays awake waiting for browsers to ask for or send data.
Node.js simply runs your JavaScript and gives it tools like files and networking. It does not force you to organize your folders in any one way.
Start a tiny server with Node.js
These few lines start a mini web server that sends a short greeting whenever someone visits.
- Save the code as
server.mjs. Thenode:httppart comes built into Node.js, so nothing extra needs installing. - Type
node server.mjsin your terminal and press Enter. - Open
http://localhost:3000(a local address pointing to your own computer) in a browser, and you will seeHello from Node.js.
This code uses only what already ships inside Node.js:
import { createServer } from 'node:http';
const server = createServer((request, response) => {
response.end('Hello from Node.js');
});
server.listen(3000);The server keeps running and listening until you press Ctrl+C in the terminal to stop it.
How is Node.js different from browser JavaScript?
It is the exact same language, but running in two different places gives it different powers.
| Compare | Node.js | Browser |
|---|---|---|
| Where it runs | On your own computer or a remote server | Inside the web browser showing a page |
| What it is great at | Reading/writing disk files, running servers, talking to databases | Updating page visuals, reacting to clicks, asking servers for data |
| What it cannot do | Edit buttons or text on a web page directly (there is no page DOM) | Freely read or edit files on your computer (for your safety) |
Because browsers and Node.js both speak JavaScript, learning one language lets you build both the front and back of a website—just remember where each piece runs.
When is Node.js a good fit?
Anytime you want JavaScript to do automatic work outside a web browser, Node.js fits well.
- Web backends: receive requests from web pages, look up data in a database, and send answers back.
- Handy command-line tools: rename hundreds of photos at once or generate starter files automatically.
- Website builder tools: many modern frontend bundlers and local dev servers run on Node.js themselves.
Using one language everywhere means less mental switching, and npm acts like a giant free parts store packed with ready-made packages from developers worldwide.
By default, Node.js uses one main brain for JavaScript code. It is super fast at juggling lots of waiting tasks (like fetching data or sending files), but heavy number-crunching (like video editing) can make other visitors wait in line. You also still need to host and maintain the server.
Common things people get wrong
Is Node.js a new programming language?
No. The language is JavaScript. Node.js is the environment that runs JavaScript.
Can Node.js only be used on servers?
No. You can run it right on your own laptop to organize files or run small scripts—no internet or server needed.
Is Node.js a framework?
No. A framework (like Express or Next.js) is like ruled notebook paper that sets rules for folders and URLs. Node.js just gives you the workshop and basic tools.
Quick quiz
Inside Node.js, can you directly change a button’s text on a web page (for example using the browser’s document.querySelector)?
No. Node.js runs on your computer or server, where there is no open web page and no browser DOM. It works with files, networks, and servers instead.
Remember this: JavaScript is the language; Node.js is the workshop that lets it run outside the browser.
Read further
These official guides are a great next step.