Node.js Introduction
Runtime environment, modules, npm, event loop, and building your first server.
Overview
Node.js is a JavaScript runtime built on Chrome's V8 engine that lets you run JavaScript on the server side.
Key Concepts
- V8 Engine — High-performance JavaScript engine from Chrome
- Event Loop — Non-blocking I/O model for handling concurrent operations
- npm — Node Package Manager for installing and managing packages
- Modules — CommonJS (
require) and ES Modules (import/export) - Global Objects —
process,__dirname,__filename
Code Examples
// http-server.js
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello from Node.js!\n');
});
server.listen(3000, () => {
console.log('Server running at http://localhost:3000/');
});
Practice
Install Node.js, create a simple HTTP server, and explore the npm ecosystem.