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: Node.js runs on a single thread by default, which means it can handle only one operation at a time per process. Clustering allows you to create multiple Node.js processes (workers) that share the same serve…
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: sync function connect() { const uri = 'mongodb://localhost:27017/mydatabase'; const client = new MongoClient(uri); try { wait client.connect(); console.log('Connected to MongoDB'); const db = client.db('myd…
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: time per process. Clustering allows you to create multiple Node.js processes (workers) that share the same server port. This way, your app can utilize multiple CPU cores and handle more requests concurrentl…
Short answer: Node.js is an open-source, cross-platform runtime environment that allows you to run JavaScript on the server side. It’s built on the V8 JavaScript engine developed by Google (the same one used in Chrome).…
Short answer: How do you create and use custom events? EventEmitter allows objects to emit named events and listen for them. Example: const EventEmitter = require('events'); const emitter = new EventEmitter(); emitter.on…
Short answer: EventEmitter allows objects to emit named events and listen for them. Example code const EventEmitter = require('events'); const emitter = new EventEmitter(); emitter.on('greet', (name) => { console.log(…
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: Process management means keeping your app running reliably, restarting it if it crashes, and managing multiple instances. PM2 is a popular Node.js process manager that: Restarts apps on crashes or code chan…
Short answer: Mongoose is an ODM (Object Data Modeling) library for MongoDB in Node.js. It provides: Schema-based data modeling Validation Middleware (hooks) Easy querying and relationship management You define schemas a…
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: const mongoose = require('mongoose'); const userSchema = new mongoose.Schema({ name: { type: String, required: true }, email: { type: String, required: true, unique: true }, age: Number, createdAt: { type:…
Short answer: Mocha is a test runner that executes your test files, organizes tests in suites (describe), and allows async testing. It does not provide assertions, so it’s often paired with assertion libraries like Chai.…
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…
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: Node.js runs on a single thread by default, which means it can handle only one operation at a time per process. Clustering allows you to create multiple Node.js processes (workers) that share the same server port. This way, your app can utilize multiple CPU cores and handle more requests concurrently. 📌 Example: Using the built-in cluster module, you can fork multiple workers.
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: sync function connect() { const uri = 'mongodb://localhost:27017/mydatabase'; const client = new MongoClient(uri); try { wait client.connect(); console.log('Connected to MongoDB'); const db = client.db('mydatabase'); // Use `db` to query collections } catch (err) { console.error(err); } finally { wait client.close(); } } connect(); Example… code sync…… function connect() { const uri =…
'mongodb://localhost:27017/mydatabase'; const client = new MongoClient(uri); try { wait client.connect(); console.log('Connected to MongoDB'); const db = client.db('mydatabase'); // Use `db` to query collections } catch (err) { console.error(err); } finally { wait client.close(); } } connect(); sync function connect() { const uri = 'mongodb://localhost:27017/mydatabase'; const client = new MongoClient(uri); try { wait client.connect(); console.log('Connected to MongoDB'); const db = client.db('mydatabase'); // Use `db` to query collections } catch (err) { console.error(err); } finally { wait client.close(); } } connect(); Example… code sync function…
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: time per process. Clustering allows you to create multiple Node.js processes (workers) that share the same server port. This way, your app can utilize multiple CPU cores and handle more requests concurrently. 📌 Example: Using the built-in cluster module, you can fork multiple workers.
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 is an open-source, cross-platform runtime environment that allows you to run JavaScript on the server side. It’s built on the V8 JavaScript engine developed by Google (the same one used in Chrome). With Node.js, you can build scalable and high-performance web applications, APIs, and even real-time services like chat apps. 📌
If you write a simple HTTP server in Node.js, you can serve a webpage without using a traditional web server like Apache: const http = require('http'); http.createServer((req, res) => { res.end('Hello from Node.js server!'); }).listen(3000);
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: How do you create and use custom events? EventEmitter allows objects to emit named events and listen for them. Example: const EventEmitter = require('events'); const emitter = new EventEmitter(); emitter.on('greet', (name) => { console.log(`Hello, ${name}!`); }); emitter.emit('greet', 'Alice'); Output: Hello, Alice! It’s fundamental for asynchronous communication in Node.js.
How do you create and use custom events? EventEmitter allows objects to emit named events and listen for them. Example: const EventEmitter = require('events');
const emitter = new EventEmitter(); emitter.on('greet', (name) => { console.log(`Hello, ${name}!`); }); emitter.emit('greet', 'Alice'); Output: Hello, Alice! It’s fundamental for asynchronous communication 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: EventEmitter allows objects to emit named events and listen for them.
const EventEmitter = require('events'); const emitter = new EventEmitter(); emitter.on('greet', (name) => { console.log(`Hello, ${name}!`); }); emitter.emit('greet', 'Alice'); Output: Hello, Alice! const emitter = new EventEmitter(); emitter.on('greet', (name) => { console.log(`Hello, ${name}!`); }); emitter.emit('greet', 'Alice'); Output: Hello, Alice! It’s fundamental for asynchronous communication 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: 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: Process management means keeping your app running reliably, restarting it if it crashes, and managing multiple instances. PM2 is a popular Node.js process manager that: Restarts apps on crashes or code changes Manages clustering (multi-core usage) Offers logs and monitoring dashboards Supports zero-downtime reloads Run your app with PM2 like this: pm2 start app.js pm2 monit
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
Node.js Node.js Tutorial · Node.js
Short answer: Mongoose is an ODM (Object Data Modeling) library for MongoDB in Node.js. It provides: Schema-based data modeling Validation Middleware (hooks) Easy querying and relationship management You define schemas and models to interact with MongoDB more intuitively.
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: const mongoose = require('mongoose'); const userSchema = new mongoose.Schema({ name: { type: String, required: true }, email: { type: String, required: true, unique: true }, age: Number, createdAt: { type: Date, default: Date.now } }); const User = mongoose.model('User', userSchema); // Usage example async function createUser() { const user = new User({ name: 'Alice', email: 'alice@example.com', age: 25 }); await…
user.save(); console.log('User saved'); }
const mongoose = require('mongoose'); const userSchema = new mongoose.Schema({ name: { type: String, required: true }, email: { type: String, required: true, unique: true }, age: Number, createdAt: { type: Date, default: Date.now } }); const User = mongoose.model('User', userSchema); // Usage example async function createUser() { const user = new User({ name: 'Alice', email: 'alice@example.com', age: 25 }); await user.save(); console.log('User saved'); }
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 is a test runner that executes your test files, organizes tests in suites (describe), and allows async testing. It does not provide assertions, so it’s often paired with assertion libraries like Chai.
A ShopNest BFF in Node.js aggregates catalog and price APIs for the React storefront.
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.
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.