Interview Q&A

Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.

4616 total questions 4516 technical 100 career & HR 4346 from PDF library

Showing 1–25 of 74

Career & HR topics

By tech stack

Mid PDF
What are process.nextTick() and setImmediate()? How do they differ?

process.nextTick() queues a callback to be invoked immediately after the current operation completes, before the event loop continues. setImmediate() queues a callback to run on the next iteration of the event loop. Exam…

Node.js Read answer
Mid PDF
What happens when an uncaught exception occurs in Node.js?

If an error (exception) is thrown but not caught, Node.js will: Print the error stack trace to the console. Immediately terminate the process to avoid unpredictable behavior. Why? Because an uncaught exception might leav…

Node.js Read answer
Mid PDF
What are common security issues in Node.js applications?

Injection attacks (SQL, NoSQL) Cross-Site Scripting (XSS) Cross-Site Request Forgery (CSRF) Broken authentication and session management Insecure handling of sensitive data (passwords, API keys) Unvalidated input data Ex…

Node.js Read answer
Mid PDF
How do you write unit tests in Node.js? Unit tests check small, isolated pieces of your code (like functions) to make sure they work

s expected. Basic example using Mocha and Chai: // calculator.js function add(a, b) { return a + b; } module.exports = add; // test/calculator.test.js const add = require('../calculator'); const { expect } = require('cha…

Node.js Read answer
Mid PDF
Why is Node.js single-threaded?

Node.js uses a single-threaded event loop to handle concurrency. This design: Simplifies programming by avoiding thread-related bugs like race conditions. Uses non-blocking I/O so a single thread can handle many connecti…

Node.js Read answer
Mid PDF
How do you prevent SQL Injection?

Always use parameterized queries or prepared statements instead of string concatenation. Example with MySQL: connection.query('SELECT * FROM users WHERE id = ?', [userId], callback); Use ORM libraries like Sequelize whic…

Node.js Read answer
Mid PDF
What are some popular testing frameworks for Node.js?

Answer: Mocha: Flexible test runner, widely used. Jest: Full-featured, zero-config, includes mocks and coverage. Jasmine: Behavior-driven development framework. AVA: Minimalistic and fast. Tape: Simple and small footprin…

Node.js Read answer
Mid PDF
How do you improve performance in a Node.js app?

Use clustering or process managers like PM2 to utilize multiple CPU cores. Implement caching (in-memory or distributed caches like Redis). Use asynchronous I/O properly (avoid blocking the event loop). Optimize database…

Node.js Read answer
Mid PDF
How does Node.js work?

Node.js operates on a single-threaded, event-driven architecture. It uses the event loop to handle multiple connections concurrently, which means it can perform non-blocking I/O operations efficiently. 📌 Real-life analo…

Node.js Read answer
Mid PDF
How does Node.js handle asynchronous code internally? Explain the event loop

phases. Node.js uses the event loop to handle async tasks without blocking. Main phases: Timers: Executes callbacks scheduled by setTimeout and setInterval. Pending callbacks: Executes I/O callbacks deferred to next iter…

Node.js Read answer
Mid PDF
When should you not use Node.js?

Node.js is awesome for I/O-heavy, real-time apps, but it’s not ideal for: CPU-intensive tasks: Heavy computations block the event loop and slow down all requests. Applications requiring multithreaded parallelism: Though…

Node.js Read answer
Mid PDF
How do you handle environment variables in production?

Use real environment variables on the server or container. Avoid committing .env files to source control. In cloud providers, set environment variables in the dashboard. Use tools like dotenv only in development. For sen…

Node.js Read answer
Mid PDF
Load it in your app:?

require('dotenv').config(); console.log(process.env.DB_PASSWORD); What interviewers expect A clear definition tied to Node.js in Node.js projects Trade-offs (performance, maintainability, security, cost) When you would a…

Node.js Read answer
Mid PDF
How do you prevent NoSQL injection?

Answer: Avoid directly inserting user input into queries. Use safe query methods (e.g., Mongoose’s query APIs). Validate and sanitize input. For example, don’t allow user input to modify query operators like $gt, $ne. Wh…

Node.js Read answer
Mid PDF
Server middleware checks the token?

📌 Middleware example: function auth(req, res, next) { const token = req.headers.authorization?.split(' ')[1]; if (!token) return res.status(401).send('Unauthorized'); try { const user = jwt.verify(token, 'secret'); req.…

Node.js Read answer
Mid PDF
What are worker threads in Node.js and when should you use them?

Answer: Worker threads run JavaScript code in parallel threads — useful for CPU-intensive tasks that block the event loop. Use them when your app needs heavy computation without blocking other requests. What interviewers…

Node.js Read answer
Mid PDF
How does garbage collection work in Node.js?

Node.js uses the V8 JavaScript engine’s garbage collector, which: Automatically frees memory that's no longer referenced. Uses a generational GC: young generation (short-lived objects) and old generation (long-lived obje…

Node.js Read answer
Mid PDF
How do you connect Node.js with MySQL/PostgreSQL? You can use native drivers or ORMs like Sequelize. Example with MySQL native driver: const mysql = require('mysql2/promise');

Answer: sync function connect() { const connection = await mysql.createConnection({ host: 'localhost', user: 'root', database: 'test' }); const [rows] = await connection.execute('SELECT * FROM users'); console.log(rows);…

Node.js Read answer
Mid PDF
What are worker threads in Node.js?

Worker threads allow you to run JavaScript code in parallel on multiple threads within the same process — useful for CPU-intensive tasks like image processing or complex calculations without blocking the main event loop.…

Node.js Read answer
Mid PDF
What are the key features of Node.js?

Asynchronous and Event-Driven: Handles multiple requests without blocking. Fast Execution: Powered by the V8 engine. Single-Threaded but Scalable: Uses event loop and callbacks for handling concurrency. Cross-platform: R…

Node.js Read answer
Mid PDF
Explain the difference between callbacks, promises, and async/await.

Callbacks: Functions passed as arguments, executed when async operation finishes. Can lead to “callback hell.” Promises: Objects representing future results; allow chaining with .then(). Async/await: Syntactic sugar over…

Node.js Read answer
Mid PDF
How do you use Docker with Node.js?

Docker packages your app and its environment into a container for consistent deployment. Basic steps: Create a Dockerfile: FROM node:18 WORKDIR /app COPY package*.json ./ RUN npm install --production COPY . . CMD ["node"…

Node.js Read answer
Mid PDF
How do you manage API keys securely?

Answer: Never hardcode keys in your source code. Store them in environment variables or secure vaults. Use .env files with .gitignore to avoid committing secrets. Rotate keys regularly. Use scopes/permissions to limit ke…

Node.js Read answer
Mid PDF
What are child processes and how are they used?

Child processes are separate processes spawned by your Node.js app to run shell commands or other programs, enabling parallel execution. const { exec } = require('child_process'); exec('ls -la', (err, stdout, stderr) =&g…

Node.js Read answer
Mid PDF
How is Node.js different from traditional web servers like Apache?

Feature Node.js Apache Thread Model Single-threaded event loop Multi-threaded I/O Non-blocking Blocking by default Performance Very high for I/O operations Good but resource intensive Use Case Real-time apps, APIs Websit…

Node.js Read answer

Node.js Node.js Tutorial · Node.js

  • process.nextTick() queues a callback to be invoked immediately after the

current operation completes, before the event loop continues.

  • setImmediate() queues a callback to run on the next iteration of the event loop.

Example:

process.nextTick(() => console.log('nextTick'));
setImmediate(() => console.log('setImmediate'));

console.log('sync');

Output:

sync

nextTick

setImmediate

nextTick runs before any I/O or timers; setImmediate runs after I/O callbacks.

Permalink & share

Node.js Node.js Tutorial · Node.js

If an error (exception) is thrown but not caught, Node.js will:
  • Print the error stack trace to the console.
  • Immediately terminate the process to avoid unpredictable behavior.

Why? Because an uncaught exception might leave the app in an inconsistent state.

Best practice: Use try/catch for synchronous code, and listen to

'uncaughtException' or 'unhandledRejection' events to log errors and gracefully

shut down:

process.on('uncaughtException', (err) => {

console.error('Uncaught Exception:', err);

process.exit(1); // Exit to avoid unstable state

});

Permalink & share

Node.js Node.js Tutorial · Node.js

  • Injection attacks (SQL, NoSQL)
  • Cross-Site Scripting (XSS)
  • Cross-Site Request Forgery (CSRF)
  • Broken authentication and session management
  • Insecure handling of sensitive data (passwords, API keys)
  • Unvalidated input data
  • Exposed stack traces or error messages
  • Security misconfigurations
Permalink & share

Node.js Node.js Tutorial · Node.js

s expected.

Basic example using Mocha and Chai:

// calculator.js

function add(a, b) {

return a + b;
}
module.exports = add;

// test/calculator.test.js

const add = require('../calculator');
const { expect } = require('chai');

describe('add function', () => {

it('should return the sum of two numbers', () => {

const result = add(2, 3);

expect(result).to.equal(5);

});

});

Run tests with:

mocha

This test suite checks if add(2,3) equals 5 — simple and effective.

Permalink & share

Node.js Node.js Tutorial · Node.js

Node.js uses a single-threaded event loop to handle concurrency. This design:

  • Simplifies programming by avoiding thread-related bugs like race conditions.
  • Uses non-blocking I/O so a single thread can handle many connections efficiently.
  • Offloads heavy tasks (file I/O, network requests) to background threads in the libuv

thread pool.

So, Node.js can handle many tasks concurrently without spawning multiple OS threads for

each.

Permalink & share

Node.js Node.js Tutorial · Node.js

  • Always use parameterized queries or prepared statements instead of string

concatenation.

Example with MySQL:

connection.query('SELECT * FROM users WHERE id = ?', [userId],

callback);

  • Use ORM libraries like Sequelize which handle this automatically.
  • Validate and sanitize inputs.
Permalink & share

Node.js Node.js Tutorial · Node.js

Answer: Mocha: Flexible test runner, widely used. Jest: Full-featured, zero-config, includes mocks and coverage. Jasmine: Behavior-driven development framework. AVA: Minimalistic and fast. Tape: Simple and small footprint.

What interviewers expect

  • A clear definition tied to Node.js in Node.js projects
  • Trade-offs (performance, maintainability, security, cost)
  • When you would and would not use it in production

Real-world example

In a production Node.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Node.js architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Node.js Node.js Tutorial · Node.js

  • Use clustering or process managers like PM2 to utilize multiple CPU cores.
  • Implement caching (in-memory or distributed caches like Redis).
  • Use asynchronous I/O properly (avoid blocking the event loop).
  • Optimize database queries and use connection pooling.
  • Minimize heavy computations in the main thread (offload with worker threads).
  • Use gzip compression for responses.
  • Properly manage memory leaks.
  • Use load balancers in production.
Permalink & share

Node.js Node.js Tutorial · Node.js

Node.js operates on a single-threaded, event-driven architecture. It uses the event loop

to handle multiple connections concurrently, which means it can perform non-blocking I/O

operations efficiently.

📌 Real-life analogy:

Think of it like a chef (Node.js) who takes multiple orders (requests) but doesn't cook each

dish one at a time. Instead, they prep and send off tasks (e.g., grilling, baking) and move on

to the next customer while waiting.

Permalink & share

Node.js Node.js Tutorial · Node.js

phases.

Node.js uses the event loop to handle async tasks without blocking.

Main phases:

  • Timers: Executes callbacks scheduled by setTimeout and setInterval.
  • Pending callbacks: Executes I/O callbacks deferred to next iteration.
  • Idle, prepare: Internal operations.
  • Poll: Retrieves new I/O events; executes I/O callbacks.
  • Check: Executes callbacks scheduled by setImmediate.
  • Close callbacks: Handles closed connections.

Tasks are processed in this order each loop iteration.

Permalink & share

Node.js Node.js Tutorial · Node.js

Node.js is awesome for I/O-heavy, real-time apps, but it’s not ideal for:

  • CPU-intensive tasks: Heavy computations block the event loop and slow down all

requests.

  • Applications requiring multithreaded parallelism: Though worker threads exist,

Node.js is not designed for parallel CPU-heavy workloads by default.

  • When you need mature libraries for complex domains: Some domains (like

machine learning) have better ecosystems in other languages.

Permalink & share

Node.js Node.js Tutorial · Node.js

  • Use real environment variables on the server or container.
  • Avoid committing .env files to source control.
  • In cloud providers, set environment variables in the dashboard.
  • Use tools like dotenv only in development.
  • For sensitive secrets, consider secret managers like AWS Secrets Manager or

HashiCorp Vault.

Permalink & share

Node.js Node.js Tutorial · Node.js

require('dotenv').config(); console.log(process.env.DB_PASSWORD);

What interviewers expect

  • A clear definition tied to Node.js in Node.js projects
  • Trade-offs (performance, maintainability, security, cost)
  • When you would and would not use it in production

Real-world example

In a production Node.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Node.js architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Node.js Node.js Tutorial · Node.js

Answer: Avoid directly inserting user input into queries. Use safe query methods (e.g., Mongoose’s query APIs). Validate and sanitize input. For example, don’t allow user input to modify query operators like $gt, $ne.

What interviewers expect

  • A clear definition tied to Node.js in Node.js projects
  • Trade-offs (performance, maintainability, security, cost)
  • When you would and would not use it in production

Real-world example

In a production Node.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Node.js architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Node.js Node.js Tutorial · Node.js

📌 Middleware example:

function auth(req, res, next) {

const token = req.headers.authorization?.split(' ')[1];
if (!token) return res.status(401).send('Unauthorized');

try {

const user = jwt.verify(token, 'secret');
req.user = user;

next();

} catch {

res.status(403).send('Invalid token');

}
}
Permalink & share

Node.js Node.js Tutorial · Node.js

Answer: Worker threads run JavaScript code in parallel threads — useful for CPU-intensive tasks that block the event loop. Use them when your app needs heavy computation without blocking other requests.

What interviewers expect

  • A clear definition tied to Node.js in Node.js projects
  • Trade-offs (performance, maintainability, security, cost)
  • When you would and would not use it in production

Real-world example

In a production Node.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Node.js architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Node.js Node.js Tutorial · Node.js

Node.js uses the V8 JavaScript engine’s garbage collector, which:

  • Automatically frees memory that's no longer referenced.
  • Uses a generational GC: young generation (short-lived objects) and old generation

(long-lived objects).

  • Runs periodically to clean up unused objects.
  • Developers usually don’t control it directly, but can monitor memory and tune via flags
if needed.
Permalink & share

Node.js Node.js Tutorial · Node.js

Answer: sync function connect() { const connection = await mysql.createConnection({ host: 'localhost', user: 'root', database: 'test' }); const [rows] = await connection.execute('SELECT * FROM users'); console.log(rows); }

What interviewers expect

  • A clear definition tied to Node.js in Node.js projects
  • Trade-offs (performance, maintainability, security, cost)
  • When you would and would not use it in production

Real-world example

In a production Node.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Node.js architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Node.js Node.js Tutorial · Node.js

Worker threads allow you to run JavaScript code in parallel on multiple threads within the

same process — useful for CPU-intensive tasks like image processing or complex

calculations without blocking the main event loop.

const { Worker } = require('worker_threads');
const worker = new Worker('./worker.js');
worker.on('message', (msg) => console.log('From worker:', msg));

worker.postMessage('start');

Permalink & share

Node.js Node.js Tutorial · Node.js

  • Asynchronous and Event-Driven: Handles multiple requests without blocking.
  • Fast Execution: Powered by the V8 engine.
  • Single-Threaded but Scalable: Uses event loop and callbacks for handling

concurrency.

  • Cross-platform: Runs on Windows, Linux, and macOS.
  • NPM (Node Package Manager): Massive ecosystem of reusable packages.
Permalink & share

Node.js Node.js Tutorial · Node.js

  • Callbacks: Functions passed as arguments, executed when async operation

finishes. Can lead to “callback hell.”

  • Promises: Objects representing future results; allow chaining with .then().
  • Async/await: Syntactic sugar over promises; lets you write async code that looks

synchronous, improving readability.

Permalink & share

Node.js Node.js Tutorial · Node.js

Docker packages your app and its environment into a container for consistent deployment.

Basic steps:

  • Create a Dockerfile:

FROM node:18

WORKDIR /app

COPY package*.json ./

RUN npm install --production

COPY . .

CMD ["node", "app.js"]

  • Build and run the container:

docker build -t my-node-app .

docker run -p 3000:3000 my-node-app

Permalink & share

Node.js Node.js Tutorial · Node.js

Answer: Never hardcode keys in your source code. Store them in environment variables or secure vaults. Use .env files with .gitignore to avoid committing secrets. Rotate keys regularly. Use scopes/permissions to limit key usage.

What interviewers expect

  • A clear definition tied to Node.js in Node.js projects
  • Trade-offs (performance, maintainability, security, cost)
  • When you would and would not use it in production

Real-world example

In a production Node.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Node.js architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Node.js Node.js Tutorial · Node.js

Child processes are separate processes spawned by your Node.js app to run shell

commands or other programs, enabling parallel execution.

const { exec } = require('child_process');

exec('ls -la', (err, stdout, stderr) => {

if (err) console.error(err);

console.log(stdout);

});

Useful for running system commands or scripts without blocking your main app.

Permalink & share

Node.js Node.js Tutorial · Node.js

Feature Node.js Apache

Thread Model Single-threaded event loop Multi-threaded

I/O Non-blocking Blocking by default

Performance Very high for I/O operations Good but resource

intensive

Use Case Real-time apps, APIs Websites, PHP apps

📌 Example:

For a chat application or API server with thousands of concurrent users, Node.js performs

better than Apache.

Permalink & share
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details