Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
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 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…
Load balancing distributes incoming requests across multiple server instances to: Improve performance Increase availability and fault tolerance In Node.js, you can: Use the cluster module to spawn workers on multiple CPU…
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);…
ssert style: ssert.equal(result, 5); 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 produc…
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.…
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…
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…
PUT: Replaces the entire resource with the data sent. If a field is missing in the request, it may get erased. Idempotent (same request repeated yields same result). PATCH: Applies partial updates to the resource. Only c…
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"…
Sequelize is a popular ORM for relational databases like MySQL, PostgreSQL, SQLite, and MSSQL. It allows you to: Define models with JavaScript classes Handle migrations and schema changes Write complex queries using Java…
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…
Supertest is a library for testing HTTP APIs, especially Express apps. It allows you to simulate HTTP requests and assert on responses. Example: const request = require('supertest'); const app = require('../app'); // You…
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…
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…
V8 engine manages memory automatically with garbage collection. To detect leaks: Use tools like Chrome DevTools, node --inspect, or heapdump. Monitor memory usage over time. Look for increasing memory without release, wh…
Backpressure happens when data is produced faster than it can be consumed downstream. In Node.js streams, it's a built-in mechanism to: Pause the readable stream when the writable stream is overwhelmed. Prevent memory ov…
Use logging libraries like winston or pino for structured logs. Separate logs into levels (info, warn, error). Output logs to files or external services (Logstash, Datadog, Splunk). Implement log rotation to prevent disk…
Use try/catch blocks with async/await to catch exceptions. Handle errors in callbacks or promise .catch() when using promise-based APIs. Log errors for debugging. Return meaningful error messages to the client without ex…
Answer: You can access environment variables using process.env. const port = process.env.PORT || 3000; These variables are set outside your app, often in your shell or deployment environment. What interviewers expect A c…
Mocking replaces real dependencies with fake versions to isolate the unit you’re testing. Common tools: Sinon: For mocks, spies, and stubs. Proxyquire: Replace dependencies when requiring modules. Jest: Has built-in mock…
sync/await provides a cleaner syntax for handling asynchronous code, making it look synchronous and easier to read compared to nested callbacks or promise chains. sync function fetchData() { try { const data = await some…
pp.js — Use the custom module const math = require('./mathUtils'); console.log(math.add(5, 3)); // Output: 8 console.log(math.subtract(10, 4)); // Output: 6 ✅ This pattern helps you break code into organized, testable, a…
synchronous operations in a single thread, constantly checking for events (e.g., incoming data, timers) and executing associated callbacks. 📌 Example: setTimeout(() => { console.log('Executed after 2 seconds'); }, 20…
nalysis. ESM is the modern standard but Node.js supports both. What interviewers expect A clear definition tied to Node.js in Node.js projects Trade-offs (performance, maintainability, security, cost) When you would and…
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.
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.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Node.js Node.js Tutorial · Node.js
Node.js uses the V8 JavaScript engine’s garbage collector, which:
(long-lived objects).
if needed.Node.js Node.js Tutorial · Node.js
Load balancing distributes incoming requests across multiple server instances to:
In Node.js, you can:
pm2 start app.js -i max
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); }
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.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Node.js Node.js Tutorial · Node.js
ssert style: ssert.equal(result, 5);
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.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
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');
Node.js Node.js Tutorial · Node.js
concurrency.
Node.js Node.js Tutorial · Node.js
finishes. Can lead to “callback hell.”
synchronous, improving readability.
Node.js Node.js Tutorial · Node.js
Example: Updating user email.
get removed.
email.
Node.js Node.js Tutorial · Node.js
Docker packages your app and its environment into a container for consistent deployment.
Basic steps:
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY . .
CMD ["node", "app.js"]
docker build -t my-node-app .
docker run -p 3000:3000 my-node-app
Node.js Node.js Tutorial · Node.js
Sequelize is a popular ORM for relational databases like MySQL, PostgreSQL, SQLite, and
MSSQL.
It allows you to:
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.
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.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Node.js Node.js Tutorial · Node.js
Supertest is a library for testing HTTP APIs, especially Express apps.
It allows you to simulate HTTP requests and assert on responses.
Example:
const request = require('supertest');
const app = require('../app'); // Your Express app
describe('GET /users', () => {
it('should return 200 and a list of users', (done) => {
request(app)
.get('/users')
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) return done(err);
done();
});
});
});
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.
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.
Node.js Node.js Tutorial · Node.js
V8 engine manages memory automatically with garbage collection.
To detect leaks:
Modules & Package Management
Node.js Node.js Tutorial · Node.js
Backpressure happens when data is produced faster than it can be consumed downstream.
In Node.js streams, it's a built-in mechanism to:
This flow control allows producers and consumers to work in sync.
Node.js Node.js Tutorial · Node.js
Node.js Node.js Tutorial · Node.js
Example:
try {
const user = await User.findById(id);
if (!user) throw new Error('User not found');
} catch (error) {
console.error(error);
res.status(500).send('Something went wrong');
}Node.js Node.js Tutorial · Node.js
Answer: You can access environment variables using process.env. const port = process.env.PORT || 3000; These variables are set outside your app, often in your shell or deployment environment.
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.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Node.js Node.js Tutorial · Node.js
Mocking replaces real dependencies with fake versions to isolate the unit you’re testing.
Common tools:
Example with Sinon:
const sinon = require('sinon');
const myModule = require('../myModule');
const dependency = require('../dependency');
describe('test with mock', () => {
it('should call dependency once', () => {
const stub = sinon.stub(dependency, 'someMethod').returns(42);
const result = myModule.doSomething();
sinon.assert.calledOnce(stub);
stub.restore();
});
});
Node.js Node.js Tutorial · Node.js
sync/await provides a cleaner syntax for handling asynchronous code, making it look
synchronous and easier to read compared to nested callbacks or promise chains.
sync function fetchData() {
try {
const data = await someAsyncFunction();
console.log(data);
} catch (err) {
console.error(err);
}
}Node.js Node.js Tutorial · Node.js
pp.js — Use the custom module
const math = require('./mathUtils');
console.log(math.add(5, 3)); // Output: 8
console.log(math.subtract(10, 4)); // Output: 6
✅ This pattern helps you break code into organized, testable, and reusable pieces — just
like using built-in or third-party libraries.
dvanced Node.js Concepts
Node.js Node.js Tutorial · Node.js
synchronous operations in a single thread, constantly checking for events (e.g., incoming
data, timers) and executing associated callbacks.
📌 Example:
setTimeout(() => {
console.log('Executed after 2 seconds');
}, 2000);
This callback is scheduled by the event loop and executed when the time is up.
Node.js Node.js Tutorial · Node.js
nalysis. ESM is the modern standard but Node.js supports both.
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.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.