JobsPing

Node.js interview practice

Covers event loop, streams, Express, error handling, scaling. Questions are written for real interviews at junior, mid and senior level.

Start a Node.js practice test

15 multiple-choice questions · 15 minutes · instant score with explanations

Sample Node.js interview questions

Three questions from the bank, with answers. The practice test draws different ones each time.

Question 1 · Buffers · junior

What does console.log(buf[0]) output when buf is created with Buffer.from('hello')?

const buf = Buffer.from('hello');
console.log(buf[0]);
  1. A.undefined
  2. B.'hello'
  3. C.104
  4. D.'h'
Show answer

C. 104

In Node.js, Buffer instances are representations of fixed-length sequences of bytes. When accessing a buffer element by index, it returns the numeric ASCII/UTF-8 byte value (104 for lowercase 'h').

Question 2 · Scaling · junior

What is the primary purpose of the cluster module in Node.js?

const cluster = require('cluster');
const http = require('http');
if (cluster.isMaster) {
  cluster.fork();
} else {
  http.createServer((req, res) => {
    res.end('Worker response');
  }).listen(8000);
}
  1. A.To convert callback-based asynchronous code into native Promises.
  2. B.To take advantage of multi-core systems by spawning worker processes that share the same server port.
  3. C.To manage environment variables across different deployment stages.
  4. D.To synchronize data between multiple remote database servers.
Show answer

B. To take advantage of multi-core systems by spawning worker processes that share the same server port.

The cluster module enables the creation of child processes (workers) that all share the same server port, allowing Node.js applications to scale across multiple CPU cores for better throughput and reliability.

Question 3 · Module System · junior

What do __dirname and __filename represent in a Node.js module?

console.log(__dirname);
console.log(__filename);
  1. A.Environment variables loaded from a .env configuration file.
  2. B.Global browser variables that return window metadata.
  3. C.CommonJS wrapper variables providing the directory path and file path of the current module.
  4. D.Constants imported automatically from the operating system module.
Show answer

C. CommonJS wrapper variables providing the directory path and file path of the current module.

__dirname represents the directory name of the current module, and __filename represents the full file path of the current module. These are wrapper variables provided by Node.js for each module.

Ready to apply? Browse remote Node.js jobs →