Node.js is an open-source, cross-platform JavaScript runtime environment that lets you run JavaScript code outside of a web browser. It’s built on Google’s V8 JavaScript engine and is commonly used for backend development.
Key points:
- JavaScript beyond the browser → Lets developers use JS for server-side applications.
- Event-driven, non-blocking I/O → Handles many concurrent connections efficiently without blocking execution, making it ideal for scalable network apps.
- Single-threaded with libuv → Uses a single thread for event loop management, with a background thread pool for async operations (e.g., file system, network).
- Package ecosystem → Comes bundled with npm, giving access to millions of open-source packages.
- Cross-platform → Works on Windows, macOS, and Linux.
Common use cases:
- Web servers and REST APIs
- Real-time applications (e.g., chat apps, games)
- Command-line tools
- Microservices
Basic example:
// hello.js
const http = require('http');
http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello, world!\n');
}).listen(3000);
console.log('Server running at http://localhost:3000/');Run with:
node hello.js