Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
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…
Short answer: 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 .…
Short 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 li…
Short answer: 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, stdou…
Short answer: 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 app…
Short answer: 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 witho…
Short answer: 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 t…
Short answer: 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 cli…
Short 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. Real-world example (Sh…
Short answer: 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…
Short answer: 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 organize…
Short answer: Node.js uses the event loop with phases (timers, I/O callbacks, idle, poll, check, close callbacks) to manage async tasks. Explain a bit more Async queues (e.g., with libraries like async.queue) allow you t…
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…
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.
Node.js Node.js Tutorial · Node.js
Short answer: 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", "app.js"] Build and run the container: docker build -t my-node-app . docker run -p 3000:3000 my-node-app
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short 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.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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
Short answer: 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, which signals leaks. Modules & Package Management
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 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 space issues. Make logs easy to search and analyze.
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 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 exposing sensitive info. 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'); }
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 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.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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 mocking capabilities. 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(); }); });
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 — 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 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.
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 event loop with phases (timers, I/O callbacks, idle, poll, check, close callbacks) to manage async tasks.
Async 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) => { await 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. Additional Important Node.js Questions & Answers Core Concepts & Runtime
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.
Install Toolliyo like an app Free
Home-screen access to tutorials, coding practice & career tools — no app store needed.
On iPhone/iPad: tap Share then Add to Home Screen.