Node.js Interview Guide
Learn about event loop, streams, middleware, RESTful APIs, and best practices for Node.js backend development.
Introduction
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. This guide covers the essential concepts you need to master for Node.js backend development interviews.
Event Loop
The event loop is the heart of Node.js. It allows Node.js to perform non-blocking I/O operations.
- Timers phase
- Pending callbacks phase
- Idle, prepare phase
- Poll phase
- Check phase
- Close callbacks phase
Streams
Streams are objects that let you read data from a source or write data to a destination in chunks.
- Readable streams
- Writable streams
- Duplex streams
- Transform streams
Express.js Basics
Express is a minimal and flexible Node.js web application framework.
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.json({ message: 'Hello World' });
});
app.post('/api/users', (req, res) => {
// Handle POST request
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});