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 123

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
Junior PDF
How do you connect Node.js to MongoDB? You typically use the MongoDB Node.js driver or an ODM like Mongoose. Basic connection example with native driver: const { MongoClient } = require('mongodb');

sync function connect() { const uri = 'mongodb://localhost:27017/mydatabase'; const client = new MongoClient(uri); try { wait client.connect(); console.log('Connected to MongoDB'); const db = client.db('mydatabase'); //…

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
Junior PDF
What is clustering in Node.js? Node.js runs on a single thread by default, which means it can handle only one operation at

time per process. Clustering allows you to create multiple Node.js processes (workers) that share the same server port. This way, your app can utilize multiple CPU cores and handle more requests concurrently. 📌 Example:…

Node.js Read answer
Junior PDF
What is Node.js?

Node.js is an open-source, cross-platform runtime environment that allows you to run JavaScript on the server side. It’s built on the V8 JavaScript engine developed by Google (the same one used in Chrome). With Node.js,…

Node.js Read answer
Junior PDF
What is the EventEmitter class? How do you create and use custom events?

EventEmitter allows objects to emit named events and listen for them. Example: const EventEmitter = require('events'); const emitter = new EventEmitter(); emitter.on('greet', (name) => { console.log(`Hello, ${name}!`)…

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
Junior PDF
What is process management and why is PM2 useful?

Process management means keeping your app running reliably, restarting it if it crashes, and managing multiple instances. PM2 is a popular Node.js process manager that: Restarts apps on crashes or code changes Manages cl…

Node.js Read answer
Junior PDF
What is Mongoose and how is it used?

Mongoose is an ODM (Object Data Modeling) library for MongoDB in Node.js. It provides: Schema-based data modeling Validation Middleware (hooks) Easy querying and relationship management You define schemas and models to i…

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
Junior PDF
How do you define schemas and models with Mongoose? const mongoose = require('mongoose'); const userSchema = new mongoose.Schema({ name: { type: String, required: true }, email: { type: String, required: true, unique: true },

ge: Number, createdAt: { type: Date, default: Date.now } }); const User = mongoose.model('User', userSchema); // Usage example sync function createUser() { const user = new User({ name: 'Alice', email: 'alice@example.com…

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
Junior PDF
What is Mocha? Mocha is a test runner that executes your test files, organizes tests in suites (describe),

Answer: nd allows async testing. It does not provide assertions, so it’s often paired with assertion libraries like Chai. What interviewers expect A clear definition tied to Node.js in Node.js projects Trade-offs (perfor…

Node.js Read answer
Junior PDF
What is PM2 and why is it used?

PM2 is a popular production process manager for Node.js applications. It helps you: Manage and keep apps alive forever (auto-restart on crashes). Run apps in cluster mode easily. Monitor resource usage (CPU, memory). Han…

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
Junior PDF
What is the V8 engine?

The V8 engine is a high-performance JavaScript engine developed by Google for Chrome. Node.js uses it to compile and run JavaScript code on the server side. It converts JS code into machine code, making it fast and effic…

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

sync function connect() {

const uri = 'mongodb://localhost:27017/mydatabase';
const client = new MongoClient(uri);

try {

wait client.connect();

console.log('Connected to MongoDB');

const db = client.db('mydatabase');

// Use `db` to query collections

} catch (err) {

console.error(err);

} finally {

wait client.close();

}
}

connect();

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

time per process. Clustering allows you to create multiple Node.js processes (workers)

that share the same server port. This way, your app can utilize multiple CPU cores and

handle more requests concurrently.

📌 Example: Using the built-in cluster module, you can fork multiple workers.

Permalink & share

Node.js Node.js Tutorial · Node.js

Node.js is an open-source, cross-platform runtime environment that allows you to run

JavaScript on the server side. It’s built on the V8 JavaScript engine developed by Google

(the same one used in Chrome). With Node.js, you can build scalable and high-performance

web applications, APIs, and even real-time services like chat apps.

📌 Example:

If you write a simple HTTP server in Node.js, you can serve a webpage without using a

traditional web server like Apache:

const http = require('http');

http.createServer((req, res) => {

res.end('Hello from Node.js server!');

}).listen(3000);

Permalink & share

Node.js Node.js Tutorial · Node.js

EventEmitter allows objects to emit named events and listen for them.

Example:

const EventEmitter = require('events');
const emitter = new EventEmitter();

emitter.on('greet', (name) => {

console.log(`Hello, ${name}!`);

});

emitter.emit('greet', 'Alice');

Output: Hello, Alice!

It’s fundamental for asynchronous communication in Node.js.

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

Process management means keeping your app running reliably, restarting it if it crashes, and

managing multiple instances.

PM2 is a popular Node.js process manager that:

  • Restarts apps on crashes or code changes
  • Manages clustering (multi-core usage)
  • Offers logs and monitoring dashboards
  • Supports zero-downtime reloads

Run your app with PM2 like this:

pm2 start app.js

pm2 monit

Permalink & share

Node.js Node.js Tutorial · Node.js

Mongoose is an ODM (Object Data Modeling) library for MongoDB in Node.js. It provides:

  • Schema-based data modeling
  • Validation
  • Middleware (hooks)
  • Easy querying and relationship management

You define schemas and models to interact with MongoDB more intuitively.

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

ge: Number,

createdAt: { type: Date, default: Date.now }

});

const User = mongoose.model('User', userSchema);

// Usage example

sync function createUser() {

const user = new User({ name: 'Alice', email: 'alice@example.com',

ge: 25 });

wait user.save();

console.log('User saved');

}
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

Answer: nd allows async testing. It does not provide assertions, so it’s often paired with assertion libraries like Chai.

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

PM2 is a popular production process manager for Node.js applications. It helps you:

  • Manage and keep apps alive forever (auto-restart on crashes).
  • Run apps in cluster mode easily.
  • Monitor resource usage (CPU, memory).
  • Handle zero-downtime reloads.

npm install pm2 -g

pm2 start app.js -i max # Runs in cluster mode with max CPU cores

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

The V8 engine is a high-performance JavaScript engine developed by Google for Chrome.

Node.js uses it to compile and run JavaScript code on the server side. It converts JS code

into machine code, making it fast and efficient.

📌 Use Case:

When you run a .js file with Node.js, the V8 engine compiles your code into machine code

behind the scenes.

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