Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: 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 re…
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: 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 quer…
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: 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'); Example code const app…
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: The event loop is the core of Node.js's non-blocking I/O operations. It handles all asynchronous operations in a single thread, constantly checking for events (e.g., incoming data, timers) and executing ass…
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: 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. Pre…
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: async/await provides a cleaner syntax for handling asynchronous code, making it look synchronous and easier to read compared to nested callbacks or promise chains. async function fetchData() { try { const d…
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: synchronous operations in a single thread, constantly checking for events (e.g., incoming data, timers) and executing associated callbacks. Explain a bit more 📌 setTimeout(() => { console.log('Executed…
Short answer: CommonJS (CJS): Uses require() and module.exports. Synchronous module loading. ES Modules: Uses import/export syntax. Supports asynchronous and static analysis. ESM is the modern standard but Node.js suppor…
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: nalysis. ESM is the modern standard but Node.js supports both. Real-world example (ShopNest) A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront. Say this in the interview D…
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…
Node.js Node.js Tutorial · Node.js
Short answer: 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 changes the fields specified. Not necessarily idempotent.
Updating user email. PUT /users/1 with { "name": "Alice" } replaces whole user — email might get removed. PATCH /users/1 with { "email": "new@example.com" } updates just the 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: 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: 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 JavaScript instead of raw SQL
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: 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(); }); }); });
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: The event loop is the core of Node.js's non-blocking I/O operations. It handles all asynchronous operations in a single thread, constantly checking for events (e.g., incoming data, timers) and executing associated callbacks. 📌
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
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: 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 overload and crashes. This flow control allows producers and consumers to work in sync.
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: async/await provides a cleaner syntax for handling asynchronous code, making it look synchronous and easier to read compared to nested callbacks or promise chains. async function fetchData() { try { const data = await someAsyncFunction(); console.log(data); } catch (err) { console.error(err); }
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: 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: synchronous operations in a single thread, constantly checking for events (e.g., incoming data, timers) and executing associated callbacks.
📌 setTimeout(() => { console.log('Executed after 2 seconds'); }, 2000); This callback is scheduled by the event loop and executed when the time is up. synchronous operations in a single thread, constantly checking for events (e.g., incoming data, timers) and executing associated callbacks. 📌
setTimeout(() => { console.log('Executed after 2 seconds'); }, 2000); This callback is scheduled by the event loop and executed when the time is up. 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. 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
Short answer: CommonJS (CJS): Uses require() and module.exports. Synchronous module loading. ES Modules: Uses import/export syntax. Supports asynchronous and static analysis. ESM is the modern standard but Node.js supports both.
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: nalysis. ESM is the modern standard but Node.js supports both.
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 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.