Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
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: 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: 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: dotenv is a library to load environment variables from a .env file into process.env. Real-world example (ShopNest) A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront. Say t…
Short answer: 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…
Short 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 Real…
Short answer: 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…
Short answer: CSRF (Cross-Site Request Forgery) tricks a user into submitting unwanted requests to a trusted site. Protection: Use CSRF tokens with forms (e.g., csurf middleware in Express). Implement same-site cookies.…
Short answer: util.promisify() converts traditional Node.js callback-style functions into functions that return promises — letting you use async/await with them. Example code const util = require('util'); const fs = requ…
Short 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. Real-world example (ShopNest) A ShopNest BFF in Node.js aggregates ca…
Short answer: 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 ap…
Short answer: sync function read() { const content = await readFile('file.txt', 'utf8'); console.log(content); } sync function read() { const content = await readFile('file.txt', 'utf8'); console.log(content); } sync fun…
Short answer: 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…
Short answer: 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 = spa…
Short answer: __dirname: Returns the directory path of the current module. __filename: Returns the full file path of the current module. 📌 Example code console.log(__dirname); // /Users/yourname/project console.log(__fi…
Short answer: EventEmitter is a core class that allows objects to emit named events and register listeners to respond. Real-world example (ShopNest) A ShopNest BFF in Node.js aggregates catalog and price APIs for the Rea…
Short answer: 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…
Short 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). Real-wo…
Short answer: Express allows multiple middleware functions to run sequentially for a request. Each calls next() to pass control to the next middleware. app.use((req, res, next) => { console.log('Middleware 1'); next()…
Short answer: pp.use((req, res, next) => { console.log('Middleware 1'); next(); }); pp.use((req, res, next) => { console.log('Middleware 2'); res.send('Done'); }); pp.use((req, res, next) => { console.log('Middl…
Short answer: dependencies: These are required for your app to run in production. 📌 Example code express, mongoose devDependencies: Only needed during development (testing, building, linting). 📌 Example: nodemon, eslin…
Short answer: Semantic Versioning (semver) is a versioning system that uses the format: MAJOR.MINOR.PATCH Example: 2.5.3 MAJOR: Breaking changes MINOR: New features, no breaking changes PATCH: Bug fixes, backwards-compat…
Short answer: The cluster module lets you fork your Node.js process to create worker processes that share the same server port, improving CPU utilization. Testing Node.js Applications Real-world example (ShopNest) A Shop…
Short answer: Ensuring incoming data matches expected format to avoid injection attacks, crashes, or invalid data storage. Real-world example (ShopNest) A ShopNest BFF in Node.js aggregates catalog and price APIs for the…
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: 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: 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: dotenv is a library to load environment variables from a .env file into process.env.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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 outputs stats like: % of lines covered % of functions covered % of branches covered Security 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: 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
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 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.readFileSync('file.txt'); // Asynchronous (non-blocking) fs.readFile('file.txt', (err, data) => { if (err) throw err; console.log(data); });
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: CSRF (Cross-Site Request Forgery) tricks a user into submitting unwanted requests to a trusted site. Protection: Use CSRF tokens with forms (e.g., csurf middleware in Express). Implement same-site cookies. Require authentication on sensitive endpoints.
const csurf = require('csurf'); app.use(csurf());
Node.js Node.js Tutorial · Node.js
Short answer: util.promisify() converts traditional Node.js callback-style functions into functions that return promises — letting you use async/await with them.
const util = require('util');
const fs = require('fs');
const readFile = util.promisify(fs.readFile);
async function read() {
const content = await readFile('file.txt', 'utf8'); console.log(content); }
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short 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.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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 production or staging after tests pass. Benefits: Catch bugs early Fast, repeatable releases Automated testing and deployment pipelines Typical pipeline steps:
Node.js Node.js Tutorial · Node.js
Short answer: sync function read() { const content = await readFile('file.txt', 'utf8'); console.log(content); } sync function read() { const content = await readFile('file.txt', 'utf8'); console.log(content); } sync function read() { const content = await readFile('file.txt', 'utf8'); console.log(content); } sync function read() { const content = await… readFile('file.txt', 'utf8'); console.log(content); }
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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...'); });
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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', '/usr']);
ls.stdout.on('data', (data) => console.log(`Output: ${data}`)); // exec example exec('ls -lh /usr', (error, stdout) => console.log(stdout));
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: __dirname: Returns the directory path of the current module. __filename: Returns the full file path of the current module. 📌
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
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: EventEmitter is a core class that allows objects to emit named events and register listeners to respond.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: 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: Manages package versions Handles dependencies…
Supports scripts to automate tasks (npm run build, npm test, 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: 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).
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: Express allows multiple middleware functions to run sequentially for a request. Each calls next() to pass control to the next middleware. app.use((req, res, next) => { console.log('Middleware 1'); next(); }); app.use((req, res, next) => { console.log('Middleware 2'); res.send('Done'); });
Express middleware authenticates JWT, then the /orders route handler creates the order.
Node.js Node.js Tutorial · Node.js
Short answer: pp.use((req, res, next) => { console.log('Middleware 1'); next(); }); pp.use((req, res, next) => { console.log('Middleware 2'); res.send('Done'); }); pp.use((req, res, next) => { console.log('Middleware 1'); next(); }); pp.use((req, res, next) => { console.log('Middleware 2'); res.send('Done'); }); pp.use((req, res, next) => { console.log('Middleware 1');… next(); }); pp.use((req, res, next) => {…
console.log('Middleware 2'); res.send('Done'); }); pp.use((req, res, next) => { console.log('Middleware 1'); next(); }); pp.use((req, res, next) => { console.log('Middleware 2'); res.send('Done'); });
Express middleware authenticates JWT, then the /orders route handler creates the order.
Node.js Node.js Tutorial · Node.js
Short answer: dependencies: These are required for your app to run in production. 📌
express, mongoose devDependencies: Only needed during development (testing, building, linting). 📌 Example: nodemon, eslint, jest 📦 These are defined in package.json: "dependencies": { "express": "^4.18.0" }, "devDependencies": { "nodemon": "^3.0.0" } ✅ Install a dev dependency with: npm install nodemon --save-dev
Node.js Node.js Tutorial · Node.js
Short answer: Semantic Versioning (semver) is a versioning system that uses the format: MAJOR.MINOR.PATCH Example: 2.5.3 MAJOR: Breaking changes MINOR: New features, no breaking changes PATCH: Bug fixes, backwards-compatible 📌 Example: If a package moves from 1.2.0 to 2.0.0, it likely has breaking changes. In package.json, you might see: "express": "^4.17.1" ^ means it can auto-update minor and patch versions, but not major ones.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: The cluster module lets you fork your Node.js process to create worker processes that share the same server port, improving CPU utilization. Testing Node.js Applications
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: Ensuring incoming data matches expected format to avoid injection attacks, crashes, or invalid data storage.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.