Fundamental and Advanced Interview Questions and Answers
Node.js
Q: What is Node.js?
A: Node.js is a runtime environment that allows JavaScript to run on the server-side. It is built on the
V8 JavaScript engine.
Q: What is the use of npm?
A: `npm` (Node Package Manager) is used to manage dependencies and install packages in a
Node.js application.
Q: What are the core modules in Node.js?
A: Some core modules are `http`, `fs`, `path`, `events`, and `url`.
Q: What is Event Loop in Node.js?
A: The event loop handles asynchronous callbacks and allows Node.js to be non-blocking.
Q: What is the difference between process.nextTick() and setImmediate()?
A: `process.nextTick()` executes code after the current operation completes, while `setImmediate()`
executes code on the next iteration of the event loop.
Q: What is the use of the 'cluster' module?
A: The 'cluster' module allows you to create child processes that share the same server port,
enabling load balancing.
Express.js
Q: What is Express.js?
A: Express.js is a lightweight web framework for Node.js used to build APIs and web applications.
Q: How do you define a route in Express?
A: app.get('/route', (req, res) => { res.send('Hello World'); });
Q: What is middleware in Express.js?
A: Middleware functions have access to request and response objects. They can modify them or
end the response cycle.
Q: How do you handle errors in Express?
A: app.use((err, req, res, next) => { res.status(500).send(err.message); });
Q: What is the difference between app.use() and app.get()?
A: `app.use()` is for middleware that applies to all routes, while `app.get()` is for handling GET
requests on a specific route.
Q: How can you secure Express apps?
A: Use HTTPS, helmet, rate limiting, and input validation to secure Express apps.
MongoDB
Q: What is MongoDB?
A: MongoDB is a NoSQL database that stores data in BSON (binary JSON) format.
Q: What is a document in MongoDB?
A: A document is a key-value pair structure, similar to a JSON object.
Q: What is a collection?
A: A collection is a group of MongoDB documents, like a table in relational databases.
Q: How do you find a document?
A: db.users.find({ name: "John" });
Q: What is indexing in MongoDB?
A: Indexing improves the speed of data retrieval operations on a collection.
Q: What is the aggregation framework?
A: The aggregation framework processes data records and returns computed results, used for
operations like sum, average, etc.
Mongoose
Q: What is Mongoose?
A: Mongoose is an ODM (Object Data Modeling) library for MongoDB and Node.js.
Q: How do you define a schema in Mongoose?
A: const userSchema = new mongoose.Schema({ name: String });
Q: How do you create a model in Mongoose?
A: const User = mongoose.model('User', userSchema);
Q: How do you perform CRUD with Mongoose?
A: User.find(), User.create(), User.updateOne(), User.deleteOne()
Q: What are virtuals in Mongoose?
A: Virtuals are properties that are not stored in MongoDB but can be computed from existing data.
Q: How do you populate references in Mongoose?
A: Use the `.populate()` method to fetch related documents based on reference fields.
MySQL
Q: What is MySQL?
A: MySQL is an open-source relational database management system based on SQL.
Q: How do you connect MySQL with Node.js?
A: Use the `mysql2` or `sequelize` package to connect Node.js with MySQL.
Q: What is a foreign key?
A: A foreign key is a field in one table that refers to the primary key in another table.
Q: Basic SQL Query?
A: SELECT * FROM users WHERE age > 18;
Q: What is normalization?
A: Normalization is the process of organizing data to reduce redundancy and improve data integrity.
Q: What are joins in SQL?
A: Joins are used to combine rows from two or more tables based on a related column.
Laravel
Q: What is Laravel?
A: Laravel is a PHP framework used for web applications following the MVC pattern.
Q: What is Artisan?
A: Artisan is the command-line interface in Laravel used for tasks like creating models, migrations,
etc.
Q: What are migrations in Laravel?
A: Migrations are used to create and modify database tables using PHP code.
Q: What is Eloquent ORM?
A: Eloquent is Laravel's built-in ORM for database interaction using models.
Q: What is a service provider in Laravel?
A: Service providers are the central place to configure and bind classes into the service container.
Q: What is a facade in Laravel?
A: Facades provide a static interface to classes that are available in the applications service
container.
React.js
Q: What is React?
A: React is a JavaScript library for building user interfaces, especially SPAs.
Q: What is JSX?
A: JSX stands for JavaScript XML. It allows HTML to be written inside JavaScript.
Q: What are hooks in React?
A: Hooks are functions like `useState`, `useEffect`, etc., that let you use state and lifecycle features
in functional components.
Q: Difference between class and functional components?
A: Class components use ES6 classes and lifecycle methods, while functional components use
hooks and are simpler.
Q: What is the virtual DOM?
A: The virtual DOM is a lightweight copy of the real DOM that React uses to improve performance
by updating only whats necessary.
Q: What is the difference between useEffect and useLayoutEffect?
A: `useEffect` runs asynchronously after rendering, `useLayoutEffect` runs synchronously after
DOM mutations.
JavaScript
Q: What are data types in JavaScript?
A: String, Number, Boolean, Object, Undefined, Null, Symbol, BigInt.
Q: What is hoisting?
A: Hoisting is JavaScript's default behavior of moving declarations to the top of the scope.
Q: What is a closure?
A: A closure is a function that remembers its lexical scope even when executed outside it.
Q: Difference between `==` and `===`?
A: `==` compares value with type coercion; `===` compares value and type strictly.
Q: What is event delegation?
A: Event delegation is a technique involving adding a single event listener to a parent element that
handles events from its children.
Q: What is the difference between call, apply, and bind?
A: `call` and `apply` invoke functions immediately, with `apply` taking arguments as an array. `bind`
returns a new function with a specified `this` value.