Node.js Tutorial

This Node.js tutorial teaches you to run JavaScript outside the browser and build servers, command-line tools and REST APIs. Node.js is a free, open-source runtime that executes JavaScript on your computer or server using Google's V8 engine, the same engine inside Chrome.

Before Node.js, JavaScript lived only in web pages. Node made it possible to use one language for both the front end and the back end.

What is Node.js Used For?

  • Web servers and REST or GraphQL APIs
  • Real-time apps such as chat and live dashboards (WebSockets)
  • Command-line tools — npm, Vite and ESLint are all written in Node
  • Build tools and scripts that automate development tasks
  • Backends for mobile apps and serverless functions

How Node.js Works

Node.js uses a single-threaded event loop with non-blocking I/O. When your code reads a file or waits for a database, Node does not sit idle. It starts the operation, moves on to other work, and runs your callback or resumes your async function when the result is ready.

This model lets a single Node process handle thousands of connections at once, which is why it is popular for APIs and real-time apps. CPU-heavy work like video encoding is a weaker fit, though worker threads can help.

Your First Node.js Program

Create a file called hello.js and run it from your terminal with node hello.js.

// hello.js
const name = 'Node.js';
console.log(`Hello from ${name}!`);
console.log('Running on', process.platform, 'with Node', process.version);
Hello from Node.js!
Running on win32 with Node v20.11.1

There is no window or document in Node because there is no web page. Instead, Node gives you objects like process, and built-in modules for files, networking, paths and more.

Node.js vs Browser JavaScript

  • Same language, different environment.
  • Browser: DOM, window, fetch, localStorage. Node: file system, process, http, child processes.
  • Node can read and write files and open network ports; browser code cannot.
  • Both support modern ES modules, async/await and fetch (Node 18+).

What This Node.js Tutorial Covers

You will install Node, learn ES modules and npm, work with files, paths and events, build an HTTP server, then move to Express to create a full REST API with middleware, environment variables and proper error handling. The last lesson is a complete project. This tutorial targets Node.js 20 or newer and uses ES modules (import/export) throughout.

Frequently asked questions

Is Node.js a programming language?

No. Node.js is a runtime environment. The language is JavaScript; Node provides the engine and the APIs to run it outside the browser.

Is Node.js frontend or backend?

Node.js is mainly used for the backend: servers, APIs and tools. It is also used during frontend development to run build tools like Vite.

Is Node.js good for beginners?

Yes, especially if you already know JavaScript. You can build a working server in a few lines and use the same language across your whole stack.

Which Node.js version should I learn?

Use the current LTS (long-term support) release, Node 20 or newer. LTS versions get security updates for years and are what most companies run.