Knowledge / Computer Science and Engineering / Back-end development with Node.js

Back-end development with Node.js

Computer Science and Engineering (B.E./B.Tech) · Web, cloud and design · free study notes for exams, placements and interviews

In short

Node.js is a server-side JavaScript runtime built on Google's V8 engine plus the C library libuv, which gives it a single-threaded event loop with non-blocking I/O. Because one thread can hold thousands of open sockets while waiting on the database or network, Node suits I/O-heavy back-ends — APIs, gateways, chat, streaming, notification services — but is a poor fit for long CPU-bound work. It is the standard back-end of the MERN stack taught in Indian university electives, AICTE "Full Stack Development" courses and almost every campus training programme, and it is asked in interviews at Flipkart, Swiggy, Zomato, Paytm, PhonePe, Razorpay, Jio, Ola, Dream11 and at every service company staffing MERN projects (TCS, Infosys, Wipro, Accenture, Cognizant). University exams test the event loop, modules, streams and Express; placement rounds test async ordering, error handling and scaling.

Explained

Architecture: runtime, event loop and the thread pool

Modules, npm and project structure

Asynchronous programming: callbacks, promises, async/await

Streams, buffers and the file system

Express.js and the HTTP layer

Scaling, performance and production operation

Key points

Formulas and examples

Little's Law: N = X × R — N = average requests in flight, X = throughput (req/s), R = average response time (s)
Utilisation law: U = X × S — S = service demand on one resource per request (s of CPU), U must stay below 1 for one thread
Single-thread capacity: X_max = 1 / S_cpu (req/s)
Cluster capacity: X_cluster = k × (1 / S_cpu) × U_target — k = worker processes (≤ vCPU count)
Thread-pool bound: X_pool = P / T — P = UV_THREADPOOL_SIZE, T = seconds of pool work per request
Sequential vs parallel awaits: R_seq = Σ tᵢ ; R_par ≈ max(tᵢ)
Stream memory ≈ highWaterMark × number of concurrent streams (bytes)
Heap needed ≈ (entries × bytes per entry) + working set; keep below --max-old-space-size

Example 1 — concurrency from Little's Law. An Express job-search API serves X = 1,200 req/s with an average response time R = 150 ms, almost all of it waiting on PostgreSQL.

Example 2 — a blocking handler saturates the loop. A route calls crypto.pbkdf2Sync costing S_cpu = 25 ms, with arrivals of 120 req/s.

Example 3 — thread-pool ceiling. Each request does one async pbkdf2 of T = 100 ms with the default P = 4.

Example 4 — streaming a large file. A 1.5 GB (1,536 MB) CSV of listings must be transformed and written out.

Example 5 — heap sizing for an in-process cache. A worker is started with --max-old-space-size=512 (512 MB old space) and caches 300,000 entries of ~1.6 KB each.

Example 6 — async ordering (classic placement question).

console.log('A');
setTimeout(() => console.log('B'), 0);
setImmediate(() => console.log('C'));
process.nextTick(() => console.log('D'));
Promise.resolve().then(() => console.log('E'));
console.log('F');

Output: A, F, D, E, B, C — synchronous lines first, then the nextTick queue, then promise microtasks, then the timers phase, then the check phase. (B before C is the usual result in the main module but is not guaranteed; inside an I/O callback setImmediate always runs before a 0 ms timer.)

AspectBlocking (sync) callNon-blocking (async) call
Thread while waitingHeld, idleReleased to other requests
Effect of 100 concurrent requestsSerialisedOverlapped
Error styletry/catcherror-first callback / rejected promise
Safe place to useStart-up, CLI scriptsRequest handlers
clusterworker_threadschild_process.fork
UnitProcess per coreThread in one processSeparate Node process
MemoryIsolated, duplicatedShared (SharedArrayBuffer)Isolated
Start-up costHigh (~tens of ms)LowHigh
Use forUsing all cores for I/O-bound HTTPCPU-bound tasksRunning a separate script/job
Node.js (Express)Java (Spring Boot)
Concurrency modelEvent loop + thread poolThread per request (virtual threads in recent versions)
Memory per connectionVery lowHigher (thread stacks)
CPU-bound workWeak on one processStrong
Typing / toolingJavaScript or TypeScriptStatic typing, mature enterprise tooling
Typical Indian useStartups, BFF/gateway layers, real-timeBanking, insurance, large enterprise cores

Where it is used

Interview questions

Common mistakes

Related topics

REST APIs · Authentication and authorisation: sessions, OAuth and JWT · Caching, queues and CDNs · Containers: Docker and Kubernetes · Front-end frameworks: React basics · System design basics for freshers

Open in the Knowledge reader →Find jobs →