Getting Started

Node.js Introduction

Discover Node.js — JavaScript on the server — and why it changed backend development forever.

What is Node.js?

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It allows you to run JavaScript outside the browser — on servers, command-line tools, desktop apps, and more.

Key Features

  • Non-blocking I/O: Handles thousands of connections simultaneously
  • Event-driven: Uses an event loop for asynchronous operations
  • Single-threaded: One thread handles all requests (unlike traditional servers)
  • npm: Access to millions of open-source packages
  • Full-stack JavaScript: Use JavaScript for both frontend and backend

The Event Loop

Node.js's most important concept. When an operation like reading a file or querying a database takes time, Node.js doesn't wait — it registers a callback and continues processing other requests. When the operation completes, the callback runs.

When to Use Node.js

  • REST APIs and microservices
  • Real-time applications (chat, live updates)
  • Streaming applications
  • Command-line tools
  • Serverless functions

Example

nodejs
// Node.js runs JavaScript on the server
console.log("Hello from Node.js!");
console.log("Node version:", process.version);
console.log("Platform:", process.platform);

// Access environment variables
const PORT = process.env.PORT || 3000;

// Node.js has access to the filesystem, network, etc.
// (browser JavaScript does not)

// Simple HTTP server
const http = require('http');

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello, World!\n');
});

server.listen(PORT, () => {
  console.log(`Server running at http://localhost:${PORT}/`);
});
Try it yourself — NODEJS