Getting Started with Node.js: Runtime, Modules, and Your First Server
Node.js lets you run JavaScript outside the browser — on servers, CLIs, and build tools. This guide explains what it actually is and gets you to a running server in a few lines.
What Node.js Is
Node is a runtime built on Chrome’s V8 engine. Its defining trait is a non-blocking, event-driven model: instead of one thread per request, a single thread handles many connections by never waiting idly for I/O.
The Event Loop in Plain Terms
When your code starts a slow operation (reading a file, querying a DB), Node hands it off and keeps working. When the result is ready, a callback runs. This is why Node excels at I/O-heavy workloads.
Modules: CommonJS vs. ES Modules
| Style | Import | Export |
|---|---|---|
| CommonJS | const x = require("x") |
module.exports = x |
| ES Modules | import x from "x" |
export default x |
Your First Server
import http from 'node:http';
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello from Node.js');
});
server.listen(3000, () => console.log('Listening on :3000'));
Run it with node server.js and visit http://localhost:3000.
Next Steps
- Learn npm to add libraries.
- Use Express instead of raw
httpfor real apps. - Understand async/await for clean asynchronous code.
Node’s superpower is concurrency without threads. Lean into async I/O and it scales beautifully.
What to Learn Next
- Express.js for routing and middleware
- npm and package.json for dependencies
- Async patterns with promises