ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

Node.js Tutorial• 6 min read

Node.js Introduction & The Event Loop

How non-blocking, asynchronous I/O handles millions of concurrent requests

Created by Ryan Dahl in 2009, Node.js is an open-source, cross-platform JavaScript runtime built on Chrome's V8 engine that revolutionized server-side development.

The Architecture of Node.js

V8 Engine: Google's high-performance C++ engine that compiles JavaScript directly into native machine code.

libuv: A C library that provides an event loop, asynchronous file I/O, networking, and thread pool capabilities.

Single-Threaded Non-Blocking: Node uses a single main thread for JavaScript execution, offloading expensive I/O operations (database queries, network calls, disk access) to system worker threads without freezing the main application.

First Node.js Program (server.js)
const http = require('http');

const PORT = 3000;

// Create an HTTP server instance
const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({
    message: 'Welcome to Codexia Node.js Cloud Runtime!',
    uptimeSeconds: process.uptime(),
    nodeVersion: process.version
  }));
});

server.listen(PORT, () => {
  console.log(`Server is listening on http://localhost:${PORT}`);
});
The native http module allows you to spin up a web server without third-party frameworks.
Pro Tip

Because Node.js executes JavaScript on the server, you can share code, data validation schemas, and types between your frontend and backend.

ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

Which C library powers Node.js event-driven, non-blocking asynchronous I/O model?