Node.
js, Express, and MongoDB Interview Questions & Answers
[Link] Interview Questions
Q: What is [Link]?
A: [Link] is a JavaScript runtime built on Chrome's V8 engine that allows you to run JavaScript on
the server-side.
Q: What is the difference between [Link] and JavaScript?
A: JavaScript runs in the browser, while [Link] runs JavaScript on the server.
Q: What are modules in [Link]?
A: Modules are reusable blocks of code. You can use built-in modules (e.g., fs, http), custom
modules, or third-party modules via npm.
Q: What is the event loop in [Link]?
A: The event loop allows [Link] to handle non-blocking I/O operations on a single thread using
callbacks and events.
Q: What is the difference between synchronous and asynchronous in [Link]?
A: Synchronous blocks further execution until the operation completes. Asynchronous does not
block execution.
Q: What is a callback function?
A: A callback is a function passed to another function and executed after the parent function
finishes.
Q: What is a Promise in [Link]?
A: A Promise represents the eventual result or failure of an asynchronous operation.
[Link] Interview Questions
Q: What is [Link]?
A: [Link] is a minimal and flexible [Link] web framework that simplifies building APIs and web
servers.
Q: How do you create a simple Express server?
A: const express = require('express');
const app = express();
[Link]('/', (req, res) => [Link]('Hello World'));
[Link](3000);
Q: What is middleware in Express?
A: Middleware functions access req, res, and next(). They can modify requests/responses or end the
cycle.
Q: Types of middleware?
A: Application-level, Router-level, Error-handling, Built-in, and Third-party.
Q: How do you handle JSON body data?
A: Use [Link]([Link]());
Q: How do you handle errors?
A: Use [Link]((err, req, res, next) => { [Link](500).send('Error'); });
Q: What are [Link], [Link], and [Link]?
A: [Link]: route params, [Link]: query string, [Link]: POST data.
MongoDB Interview Questions
Q: What is MongoDB?
A: MongoDB is a NoSQL database that stores data in flexible, JSON-like documents.
Q: Is MongoDB schemaless?
A: Yes, by default it is schemaless. Structure can vary between documents.
Q: What is a collection and a document?
A: A collection is like a table; a document is like a row.
Q: How do you connect MongoDB with [Link]?
A: Use [Link]('mongodb://localhost:27017/mydb').
Q: What is Mongoose?
A: Mongoose is an ODM for MongoDB. It defines schemas and models.
Q: How do you define a model in Mongoose?
A: const schema = new [Link]({ name: String });
const Model = [Link]('Name', schema);
Q: CRUD with Mongoose?
A: Create: [Link](), Read: [Link](), Update: [Link](), Delete:
[Link]()
Q: Difference between find() and findOne()?
A: find() returns array, findOne() returns single document.
Q: What is population in Mongoose?
A: populate() allows referencing documents in other collections.
Q: How to validate data?
A: Use schema rules like type, required, match, etc.