Performance: Why Node.js for server-side JavaScript
HIGH IMPACT
This concept impacts server response time and how quickly the server can handle many requests simultaneously.
import { createServer } from 'http'; import { readFile } from 'fs/promises'; createServer(async (req, res) => { // Non-blocking async 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 | Concurrency | Response Time | Verdict |
|---|---|---|---|---|
| Synchronous blocking I/O | Blocks event loop | Low concurrency | High response time | [X] Bad |
| Asynchronous non-blocking I/O | No blocking | High concurrency | Low response time | [OK] Good |