Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: Transactions allow multiple database operations to execute atomically — either all succeed or none do — ensuring data consistency. In MongoDB (using Mongoose): const session = await mongoose.startSession();…
Short answer: You handle errors using try/catch blocks around await statements. async function getUser() { try { const user = await getUserFromDB(); return user; } catch (error) { console.error('Error fetching user:', er…
Short answer: Non-blocking I/O means the application doesn't wait for a task (like reading a file or querying a database) to complete before moving to the next one. Node.js uses callbacks, promises, or async/await to han…
Short answer: sync queues (e.g., with libraries like async.queue) allow you to: Control concurrency (limit how many async tasks run simultaneously). Explain a bit more Queue tasks and process them in order. sync queues (…
Short answer: 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 clin…
Short answer: wait User.create([{ name: 'Bob' }], { session }); wait Order.create([{ userId: user._id }], { session }); wait session.commitTransaction(); } catch (error) { wait session.abortTransaction(); } finally { ses…
Short 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…
Short answer: database) to complete before moving to the next one. Explain a bit more Node.js uses callbacks, promises, or sync/await to handle the results when they're ready. database) to complete before moving to the n…
Short answer: Node.js searches in this order: Real-world example (ShopNest) A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront. Say this in the interview Define — one clear sentence (the…
Short 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. Real-world example (ShopNe…
Short answer: 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…
Short answer: 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…
Short 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. Real-world exa…
Short answer: const EventEmitter = require('events'); const emitter = new EventEmitter(); emitter.on('greet', (name) => { console.log(`Hello, ${name}!`); }); emitter.emit('greet', 'Alice'); // Output: Hello, Alice! Ex…
Short answer: 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:…
Short answer: Clustering runs multiple Node.js instances on different CPU cores sharing the same server port. This spreads load and uses full CPU capacity, increasing concurrency. Real-world example (ShopNest) A ShopNest…
Short answer: Node.js uses a single-threaded event loop to handle many I/O operations asynchronously, allowing it to handle thousands of concurrent connections efficiently without creating threads per connection. Real-wo…
Short answer: Deploy multiple instances on different machines or containers. Use a load balancer to distribute traffic. Share state externally (e.g., Redis) since instances are stateless. Say this in the interview Define…
Short answer: llowing it to handle thousands of concurrent connections efficiently without creating threads per connection. Real-world example (ShopNest) A ShopNest BFF in Node.js aggregates catalog and price APIs for th…
Short answer: Global variables holding references. Event listeners not removed. Closures holding onto variables. Caches growing without limits. Security & Best Practices Real-world example (ShopNest) A ShopNest BFF i…
Short answer: To update all packages to their latest safe versions based on semver: npm update To update a specific package to its latest version: npm install express@latest For a more interactive way: npx npm-check-upda…
Short answer: You can create a custom module by writing logic in a separate .js file and exporting it using module.exports. Explain a bit more 📌 Example: mathUtils.js function add(a, b) { return a + b; module.exports =…
Short answer: Use rate limiting. Validate and sanitize inputs. Avoid blocking event loop. Use security middleware like helmet. Use a reverse proxy with DDoS protection. Real-world example (ShopNest) A ShopNest BFF in Nod…
Short answer: pp.js const math = require('./mathUtils'); console.log(math.add(5, 3)); // 8 console.log(math.subtract(9, 4)); // 5 ✅ This is how you break your code into reusable pieces (modules) in Node.js. REST API Deve…
Short answer: Strip out dangerous characters. Use libraries like validator.js. Escape output in HTML contexts. Real-world example (ShopNest) A ShopNest BFF in Node.js aggregates catalog and price APIs for the React store…
Node.js Node.js Tutorial · Node.js
Short answer: Transactions allow multiple database operations to execute atomically — either all succeed or none do — ensuring data consistency. In MongoDB (using Mongoose): const session = await mongoose.startSession(); session.startTransaction(); try { await User.create([{ name: 'Bob' }], { session });
await Order.create([{ userId: user._id }], { session });
await session.commitTransaction(); } catch (error) { await session.abortTransaction(); } finally { session.endSession(); } In Sequelize (MySQL/PostgreSQL): const t = await sequelize.transaction(); try { await User.create({ name: 'Bob' }, { transaction: t });
await Order.create({ userId: user.id }, { transaction: t });
await t.commit(); } catch (error) { await t.rollback();
} Deployment & Production
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: You handle errors using try/catch blocks around await statements. async 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.
You handle errors using try/catch blocks around await statements. async 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.
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: Non-blocking I/O means the application doesn't wait for a task (like reading a file or querying a database) to complete before moving to the next one. Node.js uses callbacks, promises, or async/await to handle the results when they're ready. 📌
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.
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: 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. 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 = 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 sync queues (e.g., with libraries like async.queue) allow you to: Control concurrency……
Node.js Node.js Tutorial · Node.js
Short answer: 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 analyze performance. Set up alerts for anomalies.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: wait User.create([{ name: 'Bob' }], { session }); wait Order.create([{ userId: user._id }], { session }); wait session.commitTransaction(); } catch (error) { wait session.abortTransaction(); } finally { session.endSession(); } In Sequelize (MySQL/PostgreSQL): 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 wait User.create([{ name: 'Bob' }], { session }); wait Order.create([{ userId: user._id }], { session }); wait session.commitTransaction(); } catch (error) { wait session.abortTransaction(); } finally { session.endSession(); } In Sequelize (MySQL/PostgreSQL): 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… wait User.create([{ name: 'Bob' }], { session…
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 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.
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. 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.
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: 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. 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. 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. 📌 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. 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. 📌
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.
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 searches in this order:
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short 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.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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 browsers process: Provides info about the current Node.js process setTimeout, setInterval, etc.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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: const bcrypt = require('bcrypt');
const hash = await bcrypt.hash(password, 10); When verifying: const match = await bcrypt.compare(inputPassword, storedHash); Database Integration
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 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.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: const EventEmitter = require('events'); const emitter = new EventEmitter(); emitter.on('greet', (name) => { console.log(`Hello, ${name}!`); }); emitter.emit('greet', 'Alice'); // Output: Hello, Alice!
const EventEmitter = require('events');
const emitter = new EventEmitter(); emitter.on('greet', (name) => { console.log(`Hello, ${name}!`); }); emitter.emit('greet', 'Alice'); // Output: Hello, Alice!
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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 package system-wide, making it available in the command line anywhere. npm install -g nodemon ✅ Used for tools/CLI apps like nodemon, eslint, typescript, etc.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: Clustering runs multiple Node.js instances on different CPU cores sharing the same server port. This spreads load and uses full CPU capacity, increasing concurrency.
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 a single-threaded event loop to handle many I/O operations asynchronously, allowing it to handle thousands of concurrent connections efficiently without creating threads per connection.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: Deploy multiple instances on different machines or containers. Use a load balancer to distribute traffic. Share state externally (e.g., Redis) since instances are stateless.
Node.js Node.js Tutorial · Node.js
Short answer: llowing it to handle thousands of concurrent connections efficiently without creating threads per connection.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: Global variables holding references. Event listeners not removed. Closures holding onto variables. Caches growing without limits. Security & Best Practices
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: To update all packages to their latest safe versions based on semver: npm update To update a specific package to its latest version: npm install express@latest For a more interactive way: npx npm-check-updates -u npm install ✅ The npm-check-updates tool helps update versions in your package.json.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: You can create a custom module by writing logic in a separate .js file and exporting it using module.exports.
📌 Example: mathUtils.js function add(a, b) { return a + b; module.exports = { add, subtract }; app.js const math = require('./mathUtils'); console.log(math.add(5, 3)); // 8 console.log(math.subtract(9, 4)); // 5 ✅ This is how you break your code into reusable pieces (modules) in Node.js. REST API Development in Node.js
} function subtract(a, b) { return a - b;
}
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 rate limiting. Validate and sanitize inputs. Avoid blocking event loop. Use security middleware like helmet. Use a reverse proxy with DDoS protection.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: pp.js const math = require('./mathUtils'); console.log(math.add(5, 3)); // 8 console.log(math.subtract(9, 4)); // 5 ✅ This is how you break your code into reusable pieces (modules) in Node.js. REST API Development in Node.js pp.js const math = require('./mathUtils'); console.log(math.add(5, 3)); // 8 console.log(math.subtract(9, 4)); // 5 ✅ This is how you break your code into reusable pieces (modules) in Node.js.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: Strip out dangerous characters. Use libraries like validator.js. Escape output in HTML contexts.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.