Originally published on CodingCush.
Node.js is a free, open source runtime that lets you run JavaScript outside the browser, on your own computer or on a server. It gives the JavaScript you already write for web pages the power to read files, talk to databases, and answer requests from other computers. In short, it turns a browser language into a language that can run a whole website. This article starts where most beginners actually get stuck, then works backwards to the answer.
Your Form Works. Your Data Has Nowhere to Go.
You built a contact form. It looks good, the fields light up green when the email is valid, and the submit button shows a friendly thank you message. Then you realise something awkward: the message itself has gone nowhere. There is no inbox, no file, no database holding it, because browser JavaScript was never given a place to put it. You can validate data in the browser and display it, but you cannot save it. That is not a bug in your code. It is a wall built into the browser on purpose, and it is the exact problem Node.js was created to solve.
Why the Browser Hits a Wall
A browser runs JavaScript inside a sandbox, a sealed box that keeps web pages away from your computer. A random website must never be allowed to read your files, install software, or listen for incoming connections, and the sandbox is what stops it. That protection is a good thing. It is also the reason your form data cannot be saved by front end code alone. Something outside the sandbox has to receive the data and store it. That something is a server, and Node.js is one of the simplest ways to build one with a language you already know. It is also why tutorials suddenly switch languages halfway through: they teach JavaScript in the browser, then introduce a second language for the server. Node.js removes that switch.
Stuck Already? Check These Five Things First
Most first-hour Node.js problems are small setup mistakes, not real bugs. Before you change a line of code, run through this list.
The terminal says node is not recognised. Node.js is either not installed, or the terminal opened before the install finished. Close it, open a fresh one, and run node --version.
The server crashes with EADDRINUSE. Another program is already using port 3000, often an earlier copy of your own server. Change the port in your code to 3001, or stop the old process.
Node says it cannot find your file. You are probably running the command from the wrong folder. Use cd to move into the folder where you saved the file, then run it again.
The browser says the connection was refused. The server is not running, or the address bar has the wrong port. Check the terminal still shows your server running, and that the address matches the port in your code.
The page shows raw text instead of tidy JSON. Check the Content-Type header in your code. Without application/json, the browser treats the reply as plain text.
So What Is Node.js, Really?
Node.js is a runtime built on V8, the JavaScript engine inside Google Chrome. Ryan Dahl released it in 2009 with a simple idea: let JavaScript run on a server, not just in a browser tab. The official Node.js about page describes it as a JavaScript runtime built on Chrome's V8 engine, designed for fast, scalable network applications. It is not a framework, a library, or a new language. It is an environment that runs JavaScript on your machine. It also handles many requests at once: when it asks a database for data, it notes the request and moves on, picking up the answer when it arrives. This non-blocking style is managed by the event loop, and our guide to how the JavaScript event loop works explains it step by step.
You need Node.js 20 LTS or newer for the examples here. The current LTS release is v26.13.1, codenamed Lithium, released on 10 November 2026. The examples below were run with Node.js v24.22.1, and the outputs shown are real.
Your First Server in About Ten Lines
Here is a complete working server. It listens on port 3000 and answers every request with a small piece of JSON. Save it as server.js.
const http = require("http"); const server = http.createServer((req, res) => { res.writeHead(200, { "Content-Type": "application/json" }); res.end(JSON.stringify({ name: "Lavkush", fact: "I built my first server with Node.js" })); }); server.listen(3000, () => { console.log("Server running at http://localhost:3000"); }); Line by line: the first line loads the built-in http module, which Node.js ships with, so no install is needed. The createServer call builds a server and tells it what to do when a request arrives: send back status 200, which means success, label the reply as JSON, and end the response with one small object. The last block starts the server on port 3000 and prints a message so you know it is ready. None of this code would run in a browser, because browsers do not have the http module.
Start it from your terminal, in the folder where you saved the file:
node server.js The terminal replies with this exact line:
Server running at http://localhost:3000 Now open http://localhost:3000 in your browser, or run curl http://localhost:3000 in a second terminal. Either way, you get the same reply:
{"name":"Lavkush","fact":"I built my first server with Node.js"} That is an API: a server that hands out data instead of web pages. If the idea is still fuzzy, our guide to what an API is, explained simply walks through it with everyday examples.
The Node.js homepage.
Node.js vs Browser JavaScript: the Same Language, a Different Job
It is the same JavaScript in both places, but the two environments give it very different powers. Notice the last row: browser code runs because a page loaded, while Node.js code runs because you told it to.
| Feature | Browser JavaScript | Node.js |
|---|---|---|
| Where it runs | Inside a web page, in the browser | On your computer or a server |
| Can read and write files | No, blocked by the sandbox | Yes, with the built-in fs module |
| Can listen for requests | No | Yes, with the built-in http module |
| Has window and document | Yes | No, there is no page to control |
| Typical job | Buttons, forms, animations | Servers, APIs, tools, scripts |
The row that matters most is the last one. Browser code runs because a page loaded. Node.js code runs because you told it to, and it keeps running until you stop it. That is why your server can wait patiently for requests all day long.
What People Actually Build With It
Node.js runs the behind the scenes parts of many apps you use every day: chat apps, live dashboards, and the APIs that feed data to phone apps. Companies pick it when lots of small requests arrive at once. It is also the engine behind modern front end tools. When you build a React project, the build tools that bundle your code run on Node.js, even though the finished site runs in the browser. If you have not met React yet, our guide to what React is, explained simply shows where it fits. Node.js also ships with npm, a giant shared library of ready made code. The official introduction to Node.js is a good next read once your first server is running.
Questions Readers Keep Asking
Reader: Is Node.js a programming language?
Answer: No. The language is still JavaScript. Node.js is the runtime that lets JavaScript run outside the browser, the same way a browser lets it run inside a web page.
Reader: Is Node.js a framework like React?
Answer: No. React is a library for building user interfaces in the browser. Node.js is the platform your JavaScript runs on, and frameworks can be built on top of it.
Reader: Do I need to know JavaScript before learning Node.js?
Answer: Yes, and that is the good news. If you can write functions and work with objects in the browser, you already know most of what Node.js needs.
Reader: Can Node.js replace PHP or Python on the server?
Answer: It can, and many teams do exactly that. PHP and Python are still excellent choices. Node.js wins when your team already knows JavaScript.
Reader: What is npm, and do I need it?
Answer: npm is the package manager that comes with Node.js. It lets you install ready made code written by other developers. You do not need it for the server in this article, because the http module is built in.
Your Turn: Build a Tiny API About You
Here is your challenge. Take the server and change the JSON it returns so it describes you: your name and one true fact about yourself. Restart the server, open http://localhost:3000, and check that your fact appears. Then add a second route that answers only when the visitor asks for /about. You have just built an API and learned the core idea behind most of the modern web.
