Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
sync queues (e.g., with libraries like async.queue) allow you to: Control concurrency (limit how many async tasks run simultaneously). Queue tasks and process them in order. Example with async library: const async = requ…
Use monitoring tools like New Relic, Datadog, AppDynamics, or open-source tools like Prometheus + Grafana. Track metrics: response time, CPU/memory usage, error rates. Use Node.js built-in profilers or clinic.js to analy…
wait User.create([{ name: 'Bob' }], { session }); wait Order.create([{ userId: user._id }], { session }); wait session.commitTransaction(); } catch (error) { wait session.abortTransaction(); } finally { session.endSessio…
Answer: dotenv is a library to load environment variables from a .env file into process.env. What interviewers expect A clear definition tied to Node.js in Node.js projects Trade-offs (performance, maintainability, secur…
Test coverage shows how much of your code is tested (lines, branches, functions). Tools to measure: Istanbul/nyc: Most popular coverage tool. Jest: Has built-in coverage reports. Run coverage with nyc: nyc mocha It outpu…
Answer: sync function getUser() { try { const user = await getUserFromDB(); return user; } catch (error) { console.error('Error fetching user:', error); } } Without try/catch, unhandled promise rejections can crash your…
database) to complete before moving to the next one. Node.js uses callbacks, promises, or sync/await to handle the results when they're ready. 📌 Example: const fs = require('fs'); fs.readFile('file.txt', 'utf8', (err, d…
Node.js searches in this order: 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…
Answer: nodemon is a development tool that automatically restarts your Node.js app when file changes are detected—great for faster development cycles. It’s not recommended for production. Usage: nodemon app.js What inter…
Answer: Sanitize user inputs and outputs. Use libraries like DOMPurify for front-end. Use HTTP headers like Content Security Policy (CSP) via Helmet. Escape data before rendering in HTML. What interviewers expect A clear…
Synchronous functions block the execution until they finish. Asynchronous functions allow other code to run while waiting for operations (like I/O) to complete. // Synchronous (blocks event loop) const data = fs.readFile…
Global objects are available in all modules without the need to import them. Examples include: __dirname: Directory name of the current module __filename: Full path of the current module global: Similar to window in brow…
Answer: It specifies the entry point file of a package (default is index.js). When someone imports your package, Node.js loads the file in main. What interviewers expect A clear definition tied to Node.js in Node.js proj…
CI/CD stands for Continuous Integration and Continuous Deployment. CI: Automatically build and test your Node.js app every time you push code (e.g., GitHub Actions, Jenkins). CD: Automatically deploy the app to productio…
Answer: sync function read() { const content = await readFile('file.txt', 'utf8'); console.log(content); } What interviewers expect A clear definition tied to Node.js in Node.js projects Trade-offs (performance, maintain…
process is a global object that provides information and control over the current Node.js process. 📌 Examples: console.log(process.pid); // Process ID console.log(process.platform); // OS platform You can also handle ex…
Always hash passwords before storing (never store plaintext). Use strong, slow hashing algorithms like bcrypt, argon2, or scrypt. Add a salt to each password (bcrypt does this automatically). Use libraries like bcrypt: c…
Both create child processes, but: spawn() streams data (good for large outputs) exec() buffers data (good for small outputs) const { spawn, exec } = require('child_process'); // spawn example const ls = spawn('ls', ['-lh…
__dirname: Returns the directory path of the current module. __filename: Returns the full file path of the current module. 📌 Example: console.log(__dirname); // /Users/yourname/project console.log(__filename); // /Users…
Answer: Avoid blocking the event loop. Use asynchronous APIs. Use clustering or worker threads. Cache results where possible. Profile and fix bottlenecks. Use load balancers for scaling horizontally. What interviewers ex…
Answer: EventEmitter is a core class that allows objects to emit named events and register listeners to respond. What interviewers expect A clear definition tied to Node.js in Node.js projects Trade-offs (performance, ma…
NPM stands for Node Package Manager. It is the default package manager for Node.js and is used to install, share, and manage reusable packages or libraries. It comes pre-installed with Node.js and gives you access to a h…
Answer: Blocking happens when synchronous code takes too long, preventing other events from processing. Detect with tools like: clinic.js — Event Loop Delay tool. Manual timing (setInterval to check delay). What intervie…
Answer: const EventEmitter = require('events'); const emitter = new EventEmitter(); emitter.on('greet', (name) => { console.log(`Hello, ${name}!`); }); emitter.emit('greet', 'Alice'); // Output: Hello, Alice! What…
Local Installation (default): Installs the package into the node_modules folder of your current project. npm install lodash ✅ Used when the package is needed as part of your app's code. Global Installation: Installs the…
Node.js Node.js Tutorial · Node.js
sync queues (e.g., with libraries like async.queue) allow you to:
Example with async library:
const async = require('async');
const queue = async.queue(async (task) => {
wait doWork(task);
}, 2); // concurrency = 2
queue.push({ id: 1 });
queue.push({ id: 2 });
Node.js internally uses libuv’s thread pool for async I/O, but the event loop manages task
scheduling on the single main thread.
dditional Important Node.js Questions
& Answers
Core Concepts & Runtime
Node.js Node.js Tutorial · Node.js
like Prometheus + Grafana.
Node.js Node.js Tutorial · Node.js
wait User.create([{ name: 'Bob' }], { session });
wait Order.create([{ userId: user._id }], { session });
wait session.commitTransaction();
} catch (error) {
wait session.abortTransaction();
} finally {
session.endSession();
}
const t = await sequelize.transaction();
try {
wait User.create({ name: 'Bob' }, { transaction: t });
wait Order.create({ userId: user.id }, { transaction: t });
wait t.commit();
} catch (error) {
wait t.rollback();
}
Deployment & Production
Node.js Node.js Tutorial · Node.js
Answer: dotenv is a library to load environment variables from a .env file into process.env.
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
Test coverage shows how much of your code is tested (lines, branches, functions).
Tools to measure:
Run coverage with nyc:
nyc mocha
It outputs stats like:
Security in Node.js
Node.js Node.js Tutorial · Node.js
Answer: sync function getUser() { try { const user = await getUserFromDB(); return user; } catch (error) { console.error('Error fetching user:', error); } } Without try/catch, unhandled promise rejections can crash your app.
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
database) to complete before moving to the next one. Node.js uses callbacks, promises, or
sync/await to handle the results when they're ready.
📌 Example:
const fs = require('fs');
fs.readFile('file.txt', 'utf8', (err, data) => {
if (err) throw err;
console.log(data);
});
console.log('Reading file...');
You’ll see "Reading file..." first, even though the file is being read.
Node.js Node.js Tutorial · Node.js
Node.js searches in this order:
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
Answer: nodemon is a development tool that automatically restarts your Node.js app when file changes are detected—great for faster development cycles. It’s not recommended for production. Usage: nodemon app.js
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
Answer: Sanitize user inputs and outputs. Use libraries like DOMPurify for front-end. Use HTTP headers like Content Security Policy (CSP) via Helmet. Escape data before rendering in HTML.
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
I/O) to complete.
// Synchronous (blocks event loop)
const data = fs.readFileSync('file.txt');
// Asynchronous (non-blocking)
fs.readFile('file.txt', (err, data) => {
if (err) throw err;
console.log(data);
});
Node.js Node.js Tutorial · Node.js
Global objects are available in all modules without the need to import them. Examples
include:
Node.js Node.js Tutorial · Node.js
Answer: It specifies the entry point file of a package (default is index.js). When someone imports your package, Node.js loads the file in main.
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
CI/CD stands for Continuous Integration and Continuous Deployment.
GitHub Actions, Jenkins).
Benefits:
Typical pipeline steps:
Node.js Node.js Tutorial · Node.js
Answer: sync function read() { const content = await readFile('file.txt', 'utf8'); console.log(content); }
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
process is a global object that provides information and control over the current Node.js
process.
📌 Examples:
console.log(process.pid); // Process ID
console.log(process.platform); // OS platform
You can also handle exit events:
process.on('exit', () => {
console.log('Exiting...');
});
Node.js Node.js Tutorial · Node.js
const bcrypt = require('bcrypt');
const hash = await bcrypt.hash(password, 10);
const match = await bcrypt.compare(inputPassword, storedHash);
Database Integration
Node.js Node.js Tutorial · Node.js
Both create child processes, but:
const { spawn, exec } = require('child_process');
// spawn example
const ls = spawn('ls', ['-lh', '/usr']);
ls.stdout.on('data', (data) => console.log(`Output: ${data}`));
// exec example
exec('ls -lh /usr', (error, stdout) => console.log(stdout));Node.js Node.js Tutorial · Node.js
📌 Example:
console.log(__dirname); // /Users/yourname/project
console.log(__filename); // /Users/yourname/project/app.js
These are very useful for reading or writing files relative to the script's location.
PM and Module Management
Node.js Node.js Tutorial · Node.js
Answer: Avoid blocking the event loop. Use asynchronous APIs. Use clustering or worker threads. Cache results where possible. Profile and fix bottlenecks. Use load balancers for scaling horizontally.
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
Answer: EventEmitter is a core class that allows objects to emit named events and register listeners to respond.
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
NPM stands for Node Package Manager. It is the default package manager for Node.js and
is used to install, share, and manage reusable packages or libraries.
It comes pre-installed with Node.js and gives you access to a huge ecosystem of
open-source tools.
📌 Example Use:
npm install express
This command downloads the Express.js library into your project.
✅ NPM also:
Node.js Node.js Tutorial · Node.js
Answer: Blocking happens when synchronous code takes too long, preventing other events from processing. Detect with tools like: clinic.js — Event Loop Delay tool. Manual timing (setInterval to check delay).
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
Answer: const EventEmitter = require('events'); const emitter = new EventEmitter(); emitter.on('greet', (name) => { console.log(`Hello, ${name}!`); }); emitter.emit('greet', 'Alice'); // Output: Hello, Alice!
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
Local Installation (default):
Installs the package into the node_modules folder of your current project.
npm install lodash
Global Installation:
Installs the package system-wide, making it available in the command line anywhere.
npm install -g nodemon