SyntaxStudy
Sign Up
Node.js Introduction to Node.js
Node.js Beginner 8 min read

Introduction to Node.js

Node.js is a JavaScript runtime built on Chrome's V8 engine that allows you to run JavaScript on the server. It uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, ideal for data-intensive real-time applications.

Node.js comes with npm (Node Package Manager), the world's largest software registry.

Example
// Install Node.js from https://nodejs.org
// Check version:
node --version
npm --version

// Run a script:
node server.js

// server.js — basic HTTP server
const http = require('http');

const server = http.createServer((req, res) => {
    res.writeHead(200, { 'Content-Type': 'text/html' });

    if (req.url === '/') {
        res.end('<h1>Hello from Node.js!</h1>');
    } else if (req.url === '/about') {
        res.end('<h1>About page</h1>');
    } else {
        res.writeHead(404);
        res.end('<h1>404 Not Found</h1>');
    }
});

server.listen(3000, () => {
    console.log('Server running at http://localhost:3000');
});