Node
Node.js is a JavaScript runtime built on Chrome's V8 engine that allows you to run JavaScript on the server side, outside of a browser.
Overview
Node.js enables developers to use JavaScript for server-side programming, creating a unified language across the entire web stack. It uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js is particularly well-suited for building scalable network applications and is the foundation for many modern development tools.
Example
javascript// Simple HTTP server const http = require('http'); const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello World!'); }); server.listen(3000, () => { console.log('Server running on port 3000'); }); // Using modules const fs = require('fs'); // Read file fs.readFile('data.txt', 'utf8', (err, data) => { if (err) throw err; console.log(data); }); // Modern ES6 modules (with "type": "module" in package.json) import express from 'express'; const app = express(); app.get('/', (req, res) => { res.json({ message: 'Hello World' }); }); app.listen(3000); // Async/await with Node.js import { promises as fs } from 'fs'; async function readFile() { try { const data = await fs.readFile('data.txt', 'utf8'); console.log(data); } catch (error) { console.error(error); } }
Key Points
- JavaScript runtime for server-side code
- Built on Chrome V8 engine
- Event-driven, non-blocking I/O
- Large ecosystem (npm)
- Powers modern development tools
Learn More
- npm - Package manager
- Module - JavaScript modules
- Asynchronous - Async programming
- Node.js Docs