Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: Node.js operates on a single-threaded, event-driven architecture. Explain a bit more It uses the event loop to handle multiple connections concurrently, which means it can perform non-blocking I/O operation…
Short answer: 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: Execute…
Short answer: const mongoose = require('mongoose'); const userSchema = new mongoose.Schema({ name: { type: String, required: true }, email: { type: String, required: true, unique: true }, age: Number, createdAt: { type:…
Short answer: Mocha is a test runner that executes your test files, organizes tests in suites (describe), and allows async testing. It does not provide assertions, so it’s often paired with assertion libraries like Chai.…
Short answer: 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 deferre…
Short answer: 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. Explain a bit more Applications requiring m…
Short answer: 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 develo…
Short answer: 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: 'ali…
Short answer: require('dotenv').config(); console.log(process.env.DB_PASSWORD); require('dotenv').config(); console.log(process.env.DB_PASSWORD); require('dotenv').config(); console.log(process.env.DB_PASSWORD); require(…
Short 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, $…
Short answer: And allows async testing. It does not provide assertions, so it’s often paired with assertion libraries like Chai. Real-world example (ShopNest) A ShopNest BFF in Node.js aggregates catalog and price APIs f…
Short answer: 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…
Short answer: 📌 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, '…
Short answer: 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…
Short answer: You can use native drivers or ORMs like Sequelize. Example with MySQL native driver: const mysql = require('mysql2/promise'); async function connect() { const connection = await mysql.createConnection({ hos…
Short answer: Helmet is a middleware that sets HTTP headers to protect against common attacks: Adds Content Security Policy (CSP) Prevents MIME sniffing Protects against clickjacking Enables HSTS (HTTPS enforcement) Usag…
Short answer: Chai is an assertion library for Node.js that lets you write readable tests with different styles: Expect style (most popular): expect(result).to.equal(5); Should style: result.should.equal(5); Assert style…
Short 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. Real-world…
Short answer: 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 (l…
Short answer: 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 o…
Short 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(…
Short answer: ssert style: ssert.equal(result, 5); ssert style: ssert.equal(result, 5); ssert style: ssert.equal(result, 5); ssert style: ssert.equal(result, 5); ssert style: ssert.equal(result, 5); ssert style: ssert.eq…
Short answer: 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 ma…
Short answer: 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. Cro…
Short answer: 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: Syntac…
Node.js Node.js Tutorial · Node.js
Short answer: 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.
Node.js Node.js Tutorial · Node.js
Short answer: 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 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.
ShopNest’s Node API handles many checkout requests concurrently because I/O (DB/HTTP) is non-blocking on the event loop.
Node.js Node.js Tutorial · Node.js
Short answer: const mongoose = require('mongoose'); const userSchema = new mongoose.Schema({ name: { type: String, required: true }, email: { type: String, required: true, unique: true }, age: Number, createdAt: { type: Date, default: Date.now } }); const User = mongoose.model('User', userSchema); // Usage example async function createUser() { const user = new User({ name: 'Alice', email: 'alice@example.com', age: 25 }); await…
user.save(); console.log('User saved'); }
const mongoose = require('mongoose'); const userSchema = new mongoose.Schema({ name: { type: String, required: true }, email: { type: String, required: true, unique: true }, age: Number, createdAt: { type: Date, default: Date.now } }); const User = mongoose.model('User', userSchema); // Usage example async function createUser() { const user = new User({ name: 'Alice', email: 'alice@example.com', age: 25 }); await user.save(); console.log('User saved'); }
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: Mocha is a test runner that executes your test files, organizes tests in suites (describe), and allows async testing. It does not provide assertions, so it’s often paired with assertion libraries like Chai.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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.
ShopNest’s Node API handles many checkout requests concurrently because I/O (DB/HTTP) is non-blocking on the event loop.
Node.js Node.js Tutorial · Node.js
Short answer: 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.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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'); } 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'); } 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'); } 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:…
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: require('dotenv').config(); console.log(process.env.DB_PASSWORD); require('dotenv').config(); console.log(process.env.DB_PASSWORD); require('dotenv').config(); console.log(process.env.DB_PASSWORD); require('dotenv').config(); console.log(process.env.DB_PASSWORD);
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short 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.
Node.js Node.js Tutorial · Node.js
Short answer: And allows async testing. It does not provide assertions, so it’s often paired with assertion libraries like Chai.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 📌 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'); } }
📌 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'); }
}
Express middleware authenticates JWT, then the /orders route handler creates the order.
Node.js Node.js Tutorial · Node.js
Short answer: 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.
Node.js Node.js Tutorial · Node.js
Short answer: You can use native drivers or ORMs like Sequelize. Example with MySQL native driver: const mysql = require('mysql2/promise'); async function connect() { const connection = await mysql.createConnection({ host: 'localhost', user: 'root', database: 'test' }); const [rows] = await connection.execute('SELECT * FROM users'); console.log(rows); }
You can use native drivers or ORMs like Sequelize. Example with MySQL native driver: const mysql = require('mysql2/promise');
async function connect() { const connection = await mysql.createConnection({ host: 'localhost', user: 'root', database: 'test' }); const [rows] = await connection.execute('SELECT * FROM users'); console.log(rows); }
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: Helmet is a middleware that sets HTTP headers to protect against common attacks: Adds Content Security Policy (CSP) Prevents MIME sniffing Protects against clickjacking Enables HSTS (HTTPS enforcement) Usage: const helmet = require('helmet'); app.use(helmet());
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: Chai is an assertion library for Node.js that lets you write readable tests with different styles: Expect style (most popular): expect(result).to.equal(5); Should style: result.should.equal(5); Assert style: assert.equal(result, 5);
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short 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.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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 cores. Use external load balancers like Nginx, HAProxy, or cloud load balancers. PM2 also supports clustering with: pm2 start app.js -i max
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short 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); } 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); } 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); } 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); }
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: ssert style: ssert.equal(result, 5); ssert style: ssert.equal(result, 5); ssert style: ssert.equal(result, 5); ssert style: ssert.equal(result, 5); ssert style: ssert.equal(result, 5); ssert style: ssert.equal(result, 5); ssert style: ssert.equal(result, 5); ssert style: ssert.equal(result, 5);
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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');
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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.
ShopNest’s Node API handles many checkout requests concurrently because I/O (DB/HTTP) is non-blocking on the event loop.