Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: How do they differ? process.nextTick() queues a callback to be invoked immediately after the current operation completes, before the event loop continues. setImmediate() queues a callback to run on the next…
Short answer: Deploying means getting your app from your local machine to a live server. Explain a bit more Basic steps: Choose a hosting platform: VPS (DigitalOcean, AWS EC2), PaaS (Heroku, Vercel), or container platfor…
Short answer: You typically use the MongoDB Node.js driver or an ODM like Mongoose. Explain a bit more Basic connection example with native driver: const { MongoClient } = require('mongodb'); async function connect() { c…
Short answer: Unit tests check small, isolated pieces of your code (like functions) to make sure they work as expected. Explain a bit more Basic example using Mocha and Chai: // calculator.js function add(a, b) { return…
Short answer: process.nextTick() queues a callback to be invoked immediately after the current operation completes, before the event loop continues. Explain a bit more setImmediate() queues a callback to run on the next…
Short answer: If an error (exception) is thrown but not caught, Node.js will: Print the error stack trace to the console. Explain a bit more Immediately terminate the process to avoid unpredictable behavior. Why? Because…
Short answer: Injection attacks (SQL, NoSQL) Cross-Site Scripting (XSS) Cross-Site Request Forgery (CSRF) Broken authentication and session management Insecure handling of sensitive data (passwords, API keys) Unvalidated…
Short answer: s expected. Basic example using Mocha and Chai: // calculator.js function add(a, b) { return a + b; } module.exports = add; // test/calculator.test.js const add = require('../calculator'); const { expect }…
Short answer: Node.js uses a single-threaded event loop to handle concurrency. Explain a bit more This design: Simplifies programming by avoiding thread-related bugs like race conditions. Uses non-blocking I/O so a singl…
Short answer: Always use parameterized queries or prepared statements instead of string concatenation. Example with MySQL: connection.query('SELECT * FROM users WHERE id = ?', [userId], callback); Use ORM libraries like…
Short answer: Mocha: Flexible test runner, widely used. Jest: Full-featured, zero-config, includes mocks and coverage. Jasmine: Behavior-driven development framework. AVA: Minimalistic and fast. Tape: Simple and small fo…
Short answer: Use clustering or process managers like PM2 to utilize multiple CPU cores. Explain a bit more Implement caching (in-memory or distributed caches like Redis). Use asynchronous I/O properly (avoid blocking th…
Short answer: Node.js operates on a single-threaded, event-driven architecture. Explain a bit more It uses the event loop to handle multiple connections concurrently, which means it can perform non-blocking I/O operation…
Short answer: Explain the event loop phases. Node.js uses the event loop to handle async tasks without blocking. Main phases: Timers: Executes callbacks scheduled by setTimeout and setInterval. Pending callbacks: Execute…
Short answer: phases. Node.js uses the event loop to handle async tasks without blocking. Main phases: Timers: Executes callbacks scheduled by setTimeout and setInterval. Pending callbacks: Executes I/O callbacks deferre…
Short answer: Node.js is awesome for I/O-heavy, real-time apps, but it’s not ideal for: CPU-intensive tasks: Heavy computations block the event loop and slow down all requests. Explain a bit more Applications requiring m…
Short answer: Use real environment variables on the server or container. Avoid committing .env files to source control. In cloud providers, set environment variables in the dashboard. Use tools like dotenv only in develo…
Short answer: require('dotenv').config(); console.log(process.env.DB_PASSWORD); require('dotenv').config(); console.log(process.env.DB_PASSWORD); require('dotenv').config(); console.log(process.env.DB_PASSWORD); require(…
Short answer: Avoid directly inserting user input into queries. Use safe query methods (e.g., Mongoose’s query APIs). Validate and sanitize input. For example, don’t allow user input to modify query operators like $gt, $…
Short answer: 📌 Middleware example: function auth(req, res, next) { const token = req.headers.authorization?.split(' ')[1]; if (!token) return res.status(401).send('Unauthorized'); try { const user = jwt.verify(token, '…
Short answer: You can use native drivers or ORMs like Sequelize. Example with MySQL native driver: const mysql = require('mysql2/promise'); async function connect() { const connection = await mysql.createConnection({ hos…
Short answer: Worker threads run JavaScript code in parallel threads — useful for CPU-intensive tasks that block the event loop. Use them when your app needs heavy computation without blocking other requests. Real-world…
Short answer: Node.js uses the V8 JavaScript engine’s garbage collector, which: Automatically frees memory that's no longer referenced. Uses a generational GC: young generation (short-lived objects) and old generation (l…
Short answer: sync function connect() { const connection = await mysql.createConnection({ host: 'localhost', user: 'root', database: 'test' }); const [rows] = await connection.execute('SELECT * FROM users'); console.log(…
Short answer: Worker threads allow you to run JavaScript code in parallel on multiple threads within the same process — useful for CPU-intensive tasks like image processing or complex calculations without blocking the ma…
Node.js Node.js Tutorial · Node.js
Short answer: How do they differ? process.nextTick() queues a callback to be invoked immediately after the current operation completes, before the event loop continues. setImmediate() queues a callback to run on the next iteration of the event loop.
process.nextTick(() => console.log('nextTick')); setImmediate(() => console.log('setImmediate')); console.log('sync'); Output: sync nextTick setImmediate nextTick runs before any I/O or timers; setImmediate runs after I/O callbacks.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: Deploying means getting your app from your local machine to a live server.
Basic steps: Choose a hosting platform: VPS (DigitalOcean, AWS EC2), PaaS (Heroku, Vercel), or container platforms (Kubernetes, Docker). Set environment variables securely (don't hardcode secrets). Install dependencies using npm install --production. Run your app with a process manager (like PM2) for stability. Set up reverse proxy (using Nginx or Apache) to handle HTTPS, load balancing, and static files. Automate deployments with scripts or CI/CD pipelines.
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 typically use the MongoDB Node.js driver or an ODM like Mongoose.
Basic connection example with native driver: const { MongoClient } = require('mongodb'); async function connect() { const uri = 'mongodb://localhost:27017/mydatabase'; const client = new MongoClient(uri); try { await client.connect(); console.log('Connected to MongoDB'); const db = client.db('mydatabase'); // Use `db` to query collections } catch (err) { console.error(err); } finally { await client.close(); } } connect();
You typically use the MongoDB Node.js driver or an ODM like Mongoose. Basic connection example with native driver: const { MongoClient } = require('mongodb');
async function connect() {
const uri = 'mongodb://localhost:27017/mydatabase';
const client = new MongoClient(uri); try { await client.connect(); console.log('Connected to MongoDB'); const db = client.db('mydatabase'); // Use `db` to query collections } catch (err) { console.error(err); } finally { await client.close();
}
} connect();
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: Unit tests check small, isolated pieces of your code (like functions) to make sure they work as expected.
Basic example using Mocha and Chai: // calculator.js function add(a, b) { return a + b; const { expect } = require('chai'); describe('add function', () => { it('should return the sum of two numbers', () => { const result = add(2, 3); expect(result).to.equal(5); }); }); Run tests with: mocha This test suite checks if add(2,3) equals 5 — simple and effective.
}
module.exports = add; // test/calculator.test.js const add = require('../calculator');
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.nextTick() queues a callback to be invoked immediately after the current operation completes, before the event loop continues.
setImmediate() queues a callback to run on the next iteration of the event loop.
process.nextTick(() => console.log('nextTick')); setImmediate(() => console.log('setImmediate')); console.log('sync'); Output: sync nextTick setImmediate nextTick runs before any I/O or timers; setImmediate runs after I/O callbacks.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: If an error (exception) is thrown but not caught, Node.js will: Print the error stack trace to the console.
Immediately terminate the process to avoid unpredictable behavior. Why? Because an uncaught exception might leave the app in an inconsistent state. Best practice: Use try/catch for synchronous code, and listen to 'uncaughtException' or 'unhandledRejection' events to log errors and gracefully shut down: process.on('uncaughtException', (err) => { console.error('Uncaught Exception:', err); process.exit(1); // Exit to avoid unstable state });
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: Injection attacks (SQL, NoSQL) Cross-Site Scripting (XSS) Cross-Site Request Forgery (CSRF) Broken authentication and session management Insecure handling of sensitive data (passwords, API keys) Unvalidated input data Exposed stack traces or error messages Security misconfigurations
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: s expected. Basic example using Mocha and Chai: // calculator.js function add(a, b) { return a + b; } module.exports = add; // test/calculator.test.js const add = require('../calculator'); const { expect } = require('chai'); describe('add function', () => { it('should return the sum of two numbers', () => { const result = add(2, 3);… Explain a… bit more s…… expected. Basic example using Mocha and Chai: //…
calculator.js function add(a, b) { return a + b; } module.exports = add; // test/calculator.test.js const add = require('../calculator'); const { expect } = require('chai'); describe('add function', () => { it('should return the sum of two numbers', () => { const result = add(2, 3); expect(result).to.equal(5); }); }); Run tests with: mocha This test suite checks if add(2,3) equals 5 — simple and effective. s expected. Basic example using Mocha and Chai: // calculator.js function add(a, b) { return a + b; } module.exports = add; // test/calculator.test.js const add = require('../calculator'); const { expect } =… s expected. Basic example… }
module.exports = add; // test/calculator.test.js const add = require('../calculator');
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 concurrency.
This design: Simplifies programming by avoiding thread-related bugs like race conditions. Uses non-blocking I/O so a single thread can handle many connections efficiently. Offloads heavy tasks (file I/O, network requests) to background threads in the libuv thread pool. So, Node.js can handle many tasks concurrently without spawning multiple OS threads for each.
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 use parameterized queries or prepared statements instead of string concatenation. Example with MySQL: connection.query('SELECT * FROM users WHERE id = ?', [userId], callback); Use ORM libraries like Sequelize which handle this automatically. Validate and sanitize inputs.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: Mocha: Flexible test runner, widely used. Jest: Full-featured, zero-config, includes mocks and coverage. Jasmine: Behavior-driven development framework. AVA: Minimalistic and fast. Tape: Simple and small footprint.
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 clustering or process managers like PM2 to utilize multiple CPU cores.
Implement caching (in-memory or distributed caches like Redis). Use asynchronous I/O properly (avoid blocking the event loop). Optimize database queries and use connection pooling. Minimize heavy computations in the main thread (offload with worker threads). Use gzip compression for responses. Properly manage memory leaks. Use load balancers in production.
Node.js Node.js Tutorial · Node.js
Short answer: Node.js operates on a single-threaded, event-driven architecture.
It uses the event loop to handle multiple connections concurrently, which means it can perform non-blocking I/O operations efficiently. 📌 Real-life analogy: Think of it like a chef (Node.js) who takes multiple orders (requests) but doesn't cook each dish one at a time. Instead, they prep and send off tasks (e.g., grilling, baking) and move on to the next customer while waiting.
Node.js Node.js Tutorial · Node.js
Short answer: Explain the event loop phases. Node.js uses the event loop to handle async tasks without blocking. Main phases: Timers: Executes callbacks scheduled by setTimeout and setInterval. Pending callbacks: Executes I/O callbacks deferred to next iteration. Idle, prepare: Internal operations. Poll: Retrieves new I/O events; executes I/O callbacks. Check: Executes callbacks scheduled by setImmediate. Close callbacks: Handles…
closed connections. Tasks are processed in this order each loop iteration.
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: phases. Node.js uses the event loop to handle async tasks without blocking. Main phases: Timers: Executes callbacks scheduled by setTimeout and setInterval. Pending callbacks: Executes I/O callbacks deferred to next iteration. Idle, prepare: Internal operations. Poll: Retrieves new I/O events; executes I/O callbacks. Check: Executes callbacks… scheduled… by…… setImmediate. Close callbacks: Handles closed…
connections. Tasks are processed in this order each loop iteration.
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 is awesome for I/O-heavy, real-time apps, but it’s not ideal for: CPU-intensive tasks: Heavy computations block the event loop and slow down all requests.
Applications requiring multithreaded parallelism: Though worker threads exist, Node.js is not designed for parallel CPU-heavy workloads by default. When you need mature libraries for complex domains: Some domains (like machine learning) have better ecosystems in other languages.
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 real environment variables on the server or container. Avoid committing .env files to source control. In cloud providers, set environment variables in the dashboard. Use tools like dotenv only in development. For sensitive secrets, consider secret managers like AWS Secrets Manager or HashiCorp Vault.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: require('dotenv').config(); console.log(process.env.DB_PASSWORD); require('dotenv').config(); console.log(process.env.DB_PASSWORD); require('dotenv').config(); console.log(process.env.DB_PASSWORD); require('dotenv').config(); console.log(process.env.DB_PASSWORD);
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 directly inserting user input into queries. Use safe query methods (e.g., Mongoose’s query APIs). Validate and sanitize input. For example, don’t allow user input to modify query operators like $gt, $ne.
Node.js Node.js Tutorial · Node.js
Short answer: 📌 Middleware example: function auth(req, res, next) { const token = req.headers.authorization?.split(' ')[1]; if (!token) return res.status(401).send('Unauthorized'); try { const user = jwt.verify(token, 'secret'); req.user = user; next(); } catch { res.status(403).send('Invalid token'); } }
📌 Middleware example: function auth(req, res, next) { const token = req.headers.authorization?.split(' ')[1];
if (!token) return res.status(401).send('Unauthorized'); try { const user = jwt.verify(token, 'secret');
req.user = user; next(); } catch { res.status(403).send('Invalid token'); }
}
Express middleware authenticates JWT, then the /orders route handler creates the order.
Node.js Node.js Tutorial · Node.js
Short answer: You can use native drivers or ORMs like Sequelize. Example with MySQL native driver: const mysql = require('mysql2/promise'); async function connect() { const connection = await mysql.createConnection({ host: 'localhost', user: 'root', database: 'test' }); const [rows] = await connection.execute('SELECT * FROM users'); console.log(rows); }
You can use native drivers or ORMs like Sequelize. Example with MySQL native driver: const mysql = require('mysql2/promise');
async function connect() { const connection = await mysql.createConnection({ host: 'localhost', user: 'root', database: 'test' }); const [rows] = await connection.execute('SELECT * FROM users'); console.log(rows); }
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: Worker threads run JavaScript code in parallel threads — useful for CPU-intensive tasks that block the event loop. Use them when your app needs heavy computation without blocking other requests.
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 V8 JavaScript engine’s garbage collector, which: Automatically frees memory that's no longer referenced. Uses a generational GC: young generation (short-lived objects) and old generation (long-lived objects). Runs periodically to clean up unused objects. Developers usually don’t control it directly, but can monitor memory and tune via flags if needed.
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 connect() { const connection = await mysql.createConnection({ host: 'localhost', user: 'root', database: 'test' }); const [rows] = await connection.execute('SELECT * FROM users'); console.log(rows); } sync function connect() { const connection = await mysql.createConnection({ host: 'localhost', user: 'root',… database: 'test' }); const [rows]…… = await connection.execute('SELECT * FROM users'); console.
log(rows); } sync function connect() { const connection = await mysql.createConnection({ host: 'localhost', user: 'root', database: 'test' }); const [rows] = await connection.execute('SELECT * FROM users'); console.log(rows); } sync function connect() { const connection = await mysql.createConnection({ host: 'localhost', user: 'root',… database: 'test' }); const [rows] = await connection.execute('SELECT * FROM users'); console.log(rows); }
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: Worker threads allow you to run JavaScript code in parallel on multiple threads within the same process — useful for CPU-intensive tasks like image processing or complex calculations without blocking the main event loop. const { Worker } = require('worker_threads');
const worker = new Worker('./worker.js');
worker.on('message', (msg) => console.log('From worker:', msg)); worker.postMessage('start');
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.