arrow_back Back to Curriculum
memory

Node.js

JavaScript runtime built on Chrome's V8 JavaScript engine.

Interview Questions

25 Total
Q1.

What is the difference between Node.js and JavaScript?

Easy

Node.js is a runtime environment for JavaScript, allowing developers to run JavaScript on the server-side, whereas JavaScript is a programming language.

Q2.

What is the purpose of the package.json file in a Node.js project?

Easy

The package.json file contains metadata for the project, including dependencies, scripts, and version information.

Q3.

How do you handle errors in Node.js?

Medium

Errors in Node.js can be handled using try-catch blocks, error-first callbacks, and promise rejections.

Q4.

What is the difference between synchronous and asynchronous code in Node.js?

Medium

Synchronous code executes one task at a time, whereas asynchronous code executes multiple tasks concurrently, using callbacks, promises, or async/await.

Q5.

What is a callback function in Node.js?

Easy

A callback function is a function passed as an argument to another function, executed after a specific operation is completed.

Q6.

What is the purpose of the npm init command?

Easy

The npm init command initializes a new Node.js project, creating a package.json file with default values.

Q7.

How do you install dependencies in a Node.js project?

Easy

Dependencies in a Node.js project can be installed using the npm install command, specifying the package name and version.

Q8.

What is the difference between require and import in Node.js?

Medium

Require is used for CommonJS modules, whereas import is used for ES6 modules.

Q9.

What is a Node.js module?

Easy

A Node.js module is a reusable piece of code that exports specific functionality, which can be imported and used in other parts of the application.

Q10.

How do you create a new Node.js module?

Easy

A new Node.js module can be created by defining a JavaScript file that exports specific functions or variables using the module.exports object.

Q11.

What is the purpose of the process object in Node.js?

Medium

The process object provides information about the current Node.js process, including environment variables, arguments, and standard input/output streams.

Q12.

How do you handle environment variables in a Node.js application?

Medium

Environment variables in a Node.js application can be accessed using the process.env object, and set using the dotenv package or command-line arguments.

Q13.

What is a promise in Node.js?

Medium

A promise in Node.js is an object that represents the result of an asynchronous operation, which can be either fulfilled or rejected.

Q14.

How do you use async/await in Node.js?

Medium

Async/await in Node.js is used to write asynchronous code that looks synchronous, using the async keyword to define asynchronous functions and the await keyword to wait for promises to settle.

Q15.

What is the difference between a promise and a callback?

Medium

A promise is an object that represents the result of an asynchronous operation, whereas a callback is a function passed as an argument to another function, executed after a specific operation is completed.

Q16.

How do you handle errors in promises?

Medium

Errors in promises can be handled using the catch method, which is called when a promise is rejected.

Q17.

What is the purpose of the express.js framework?

Easy

The express.js framework is a popular Node.js web framework that provides a flexible and modular way to build web applications.

Q18.

How do you create a new express.js application?

Easy

A new express.js application can be created by requiring the express module, creating a new instance of the express class, and defining routes and middleware functions.

Q19.

What is the difference between a route and a middleware function in express.js?

Medium

A route in express.js is a function that handles a specific HTTP request, whereas a middleware function is a function that can be executed before or after a route, modifying the request or response objects.

Q20.

How do you handle requests and responses in express.js?

Medium

Requests and responses in express.js can be handled using the req and res objects, which provide methods for accessing request data and sending responses.

Q21.

What is the purpose of the body-parser middleware in express.js?

Medium

The body-parser middleware in express.js is used to parse the request body, allowing developers to access request data in the req.body object.

Q22.

How do you use sessions in express.js?

Medium

Sessions in express.js can be used to store user data across multiple requests, using the express-session middleware.

Q23.

What is the purpose of the mongoose library in Node.js?

Medium

The mongoose library is a popular ODM (Object Data Modeling) library for MongoDB, providing a simple and intuitive way to interact with MongoDB databases in Node.js applications.

Q24.

How do you connect to a MongoDB database using mongoose?

Medium

A MongoDB database can be connected to using mongoose by requiring the mongoose module, creating a new instance of the mongoose class, and calling the connect method with the database URL.

Q25.

What is the difference between a model and a schema in mongoose?

Hard

A model in mongoose is a class that represents a MongoDB collection, whereas a schema is a definition of the structure of the data in the collection.