Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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:…
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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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.