Easy interview questions in Node.js & Express, page 2
Unit, integration, and E2E tests explained
Unit tests isolate one function with dependencies mocked, integration tests exercise several units together (route plus DB), E2E tests drive the whole running system.
Writing a basic Jest unit test
Import the function, group cases with describe, define each case with it or test, assert with expect and a matcher like toBe, covering normal and edge inputs.
Purpose of Helmet middleware in Express
Helmet sets safe response headers like X-Content-Type-Options, HSTS, and CSP, mitigating MIME-sniffing, clickjacking, and protocol downgrade.
Preventing XSS when rendering user content in templates
The risk is XSS; default to escaped interpolation (EJS <%= %>, Pug #{}) so HTML is encoded, and avoid raw output (<%- %>) for untrusted data.
What is a Node.js Stream and why use one
A stream processes data in chunks over time, so memory stays bounded and work starts before all data arrives; ideal for large files and network IO.
Purpose of the Node.js cluster module
Cluster forks worker processes sharing one listening port, so requests spread across CPU cores via the OS, raising throughput and adding resilience.
HTTP request-response versus WebSocket connections?
HTTP is request-initiated, pull-based, client waits for response. WebSocket is persistent, bidirectional, either side sends data anytime.
Socket.IO emit methods: socket, io, broadcast differences?
Socket.emit() sends to one client, broadcast.emit() to all except sender, io.emit() to all.
How to add Socket.IO to an Express application?
Create HTTP server with express(), attach Socket.IO to it, listen on server not app, define event handlers.
Environment configuration and secrets management in Node.js?
Use environment variables, load from .env file (dev only), never commit secrets.
What does PM2 do for Node.js applications?
PM2 restarts crashed processes and manages multiple workers.
How does NODE_ENV=production change Express behavior?
NODE_ENV is a convention signal, production disables verbose logging and enables caching.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles