Performance: What is Node.js
MEDIUM IMPACT
Node.js affects server-side performance, impacting how fast backend code executes and responds to requests.
const { createServer } = require('http');
const { readFile } = require('fs/promises');
createServer(async (req, res) => {
// Non-blocking asynchronous file read
const data = await readFile('file.txt');
res.end(data);
}).listen(3000);const http = require('http'); http.createServer((req, res) => { // Blocking synchronous file read const data = require('fs').readFileSync('file.txt'); res.end(data); }).listen(3000);
| Pattern | Event Loop Blocking | I/O Handling | Scalability | Verdict |
|---|---|---|---|---|
| Synchronous blocking code | Blocks event loop | Serial, slow | Poor under load | [X] Bad |
| Asynchronous non-blocking code | Keeps event loop free | Parallel, fast | Good under load | [OK] Good |