0% found this document useful (0 votes)
60 views18 pages

Mern Questions1

The document contains a series of questions and answers related to Node.js, Express, React, and MongoDB, focusing on core concepts and functionalities. It covers topics such as creating Node.js projects, handling HTTP requests, using the MERN stack, and managing state in React applications. The questions also address error handling, asynchronous operations, and best practices for deploying applications.

Uploaded by

ommishraa13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views18 pages

Mern Questions1

The document contains a series of questions and answers related to Node.js, Express, React, and MongoDB, focusing on core concepts and functionalities. It covers topics such as creating Node.js projects, handling HTTP requests, using the MERN stack, and managing state in React applications. The questions also address error handling, asynchronous operations, and best practices for deploying applications.

Uploaded by

ommishraa13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 18

Which of the following is a core module in Node.js?

a) fs

b) express

c) mongoose

d) react

How do you create a new Node.js project?

a) npm init

b) npm start

c) node init

d) npm create

What does the Node.js event loop do?

a) Handles network requests

b) Handles asynchronous code execution

c) Executes synchronous code

d) All of the above

Which of the following is used to handle HTTP requests in Node.js?

a) http module

b) express module

c) url module

d) fs module
What command is used to install Node.js modules?

a) node install

b) npm install

c) npm add

d) node modules install

Which of the following is used to create a simple HTTP server in Node.js?

a) http.createServer()

b) express.createServer()

c) node.createServer()

d) server.createServer()

Which of the following Node.js modules is used to work with file systems?

a) fs

b) url

c) http

d) buffer

Which of the following is NOT an advantage of using Node.js?

a) Non-blocking I/O

b) Single-threaded event loop

c) Built-in scaling and threading support

d) High performance for I/O-heavy operations


Which method is used to read a file asynchronously in Node.js?

a) fs.readFileSync()

b) fs.readFile()

c) fs.readFileAsync()

d) fs.read()

Which event is emitted when a Node.js server starts listening?

a) start

b) listening

c) ready

d) connection

Which of the following describes the MERN stack?

a) MongoDB, Express.js, React, Node.js

b) MySQL, Express.js, React, Node.js

c) MongoDB, Express.js, Ruby, Node.js

d) MongoDB, Express.js, React, Python

In the MERN stack, which technology is used for the database layer?

a) MongoDB

b) MySQL

c) PostgreSQL

d) SQLite
Which component in the MERN stack handles the server-side routing?

a) Express.js

b) React

c) Node.js

d) MongoDB

Which of the following is used to create a user interface in MERN?

a) React

b) Express.js

c) Node.js

d) MongoDB

In the MERN stack, which technology is responsible for backend logic?

a) Node.js

b) React

c) MongoDB

d) Express.js

Which is the main role of MongoDB in the MERN stack?

a) To manage routing

b) To handle database storage

c) To build the user interface

d) To run the server


Which package is used for connecting Node.js to MongoDB?

a) mongoose

b) mysql

c) pg

d) express-mongo

Which React feature is commonly used to fetch data from an API in the MERN stack?

a) useEffect

b) componentDidMount

c) fetch()

d) axios

Which Node.js feature is used to handle HTTP requests and responses in the MERN stack?

a) Express.js

b) React

c) MongoDB

d) Axios

How does MongoDB handle data?

a) Tables

b) Collections

c) Documents

d) Arrays
How do you handle asynchronous operations in Node.js?

a) Promises

b) Callbacks

c) async/await

d) All of the above

Which of the following is used to handle URL routing in Express?

a) express.Router()

b) express.URL()

c) express.Route()

d) express.Server()

How do you handle errors in Express?

a) Use next() in middleware

b) Use catch() in promises

c) Return an error response

d) All of the above

How can you handle HTTP POST data in Express?

a) Using req.body

b) Using req.params

c) Using req.query
d) Using req.data

Which Node.js module is used to create a simple HTTP server in Express?

a) http

b) server

c) node

d) express

Which method is used in Express.js to return a JSON response?

a) res.sendJSON()

b) res.json()

c) res.send()

d) res.write()

How do you connect React with an Express backend?

a) Using fetch API

b) Using Axios

c) Using WebSockets

d) All of the above

How does React handle user inputs?

a) State

b) Props
c) UseState hook

d) All of the above

How do you perform CRUD operations in MongoDB from a React app?

a) Using Axios to call Express APIs

b) Using MongoDB client in React

c) Directly through Mongoose in React

d) React cannot perform CRUD operations

What is the purpose of Redux in React applications?

a) To manage state globally

b) To make API calls

c) To fetch data

d) To connect to the database

Which of the following libraries is commonly used for making HTTP requests in React?

a) axios

b) fetch

c) superagent

d) All of the above

How do you pass data between React components?

a) Props

b) State

c) Context API
d) All of the above

How do you handle asynchronous code in React?

a) Promises

b) async/await

c) setTimeout

d) Both a and b

How do you send data from React to Express?

a) Using the GET method

b) Using the POST method

c) Using WebSockets

d) Using LocalStorage

What is the purpose of useEffect in React?

a) To handle state updates

b) To perform side effects (like fetching data, subscriptions)

c) To manage props

d) To trigger re-renders

How do you make a POST request from a React component to an Express server?

a) Using axios.post() or fetch()

b) Using window.location

c) Using react-router
Which hook in React is used to store a value in the component’s state?

a) useState

b) useEffect

c) useReducer

d) useRef

What is the primary difference between props and state in React?

a) Props are mutable, and state is immutable

b) Props are passed to a component, state is managed within a component

c) Props are used for events, and state is used for data

d) There is no difference

What does the useEffect hook depend on to re-run?

a) State changes

b) Props changes

c) Both state and props changes

d) A specified dependency array

How do you bind an event handler in React to a component's method?

a) Using the bind() method in the constructor

b) Using the arrow function syntax

c) Both a and b

d) Using this.onClick in JSX

Which of the following is used to define schema in Mongoose?


a) mongoose.Schema()

b) mongoose.model()

c) mongoose.SchemaTypes()

d) mongoose.config()

Which method is used to insert a new document in MongoDB using Mongoose?

a) save()

b) insert()

c) add()

d) create()

Which of the following is true about Mongoose validation?

a) Mongoose validation occurs before saving the document

b) Mongoose validation occurs after saving the document

c) Validation is optional in Mongoose

d) Mongoose doesn't support validation

Which of the following is used to query documents in Mongoose?

a) find()

b) query()

c) select()

d) get()

In Mongoose, what is the method to update a document?


a) updateOne()

b) updateMany()

c) findByIdAndUpdate()

d) All of the above

Which of the following can be used to create a new document in Mongoose?

a) new model()

b) model.create()

c) model.save()

d) Both a and b

Which method in Mongoose is used to remove a document by its ID?

a) remove()

b) delete()

c) deleteOne()

d) removeOne()

Which of the following can be used to define default values for fields in a Mongoose schema?

a) default

b) defaultValue

c) initial

d) value

In Mongoose, what is the purpose of the populate() method?

a) To update documents
b) To populate a field with values from another collection

c) To query for documents

d) To delete documents

Which of the following is true about indexes in MongoDB?

a) Indexes improve the performance of queries

b) Indexes increase storage space usage

c) Indexes slow down write operations

d) All of the above

What is the purpose of middleware in Express.js?

a) To handle HTTP requests

b) To handle errors

c) To modify requests and responses

d) All of the above

Which method is used in Express to serve static files like images or CSS?

a) app.use(express.static())

b) express.static()

c) express.serveStatic()

d) serveStatic()

How do you handle route parameters in Express.js?

a) Using req.body
b) Using req.params

c) Using req.query

d) Using req.route

Which HTTP method is used to update a resource in Express?

a) GET

b) PUT

c) DELETE

d) PATCH

Which of the following is the correct syntax for defining a route in Express?

a) app.route('/path').method()

b) app.method('/path')

c) app.get('/path', function)

d) Both a and c

Which Node.js module is commonly used to handle HTTP requests and responses?

a) http

b) express

c) fs

d) url

How do you parse URL-encoded data in Express?

a) app.use(express.urlencoded())
b) app.use(urlParser())

c) app.use(express.bodyParser())

d) app.use(express.urlencodedParser())

Which method is used to define a route handler for a specific HTTP method (e.g., POST) in Express?

a) app.route()

b) app.method()

c) app.handle()

d) app.request()

What is the default behavior of Express when an error occurs in middleware?

a) Error is thrown immediately

b) Error is passed to the next middleware using next()

c) Express will ignore the error

d) Express logs the error and continues execution

Which of the following is used to handle asynchronous operations in Express?

a) async/await

b) Promises

c) Callbacks

d) All of the above

Which of the following platforms can be used to deploy a MERN stack application?

a) Heroku
b) Netlify

c) AWS

d) All of the above

Which command is used to run a production build of a React app?

a) npm start

b) npm run build

c) react-scripts build

d) node server

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

a) Using .env files with the dotenv package

b) Using the config.json file

c) Setting environment variables in the terminal

d) Both a and c

How can you avoid hardcoding sensitive data in the MERN stack?

a) Use environment variables

b) Use hardcoded values in the source code

c) Use external configuration files

d) Both a and c

Which of the following is a common method of authentication in MERN applications?

a) JWT (JSON Web Tokens)

b) OAuth
c) Sessions

d) All of the above

What is the purpose of the cors middleware in a MERN stack application?

a) To handle HTTP headers for cross-origin requests

b) To serve static files

c) To parse incoming request bodies

d) To log requests and errors

What is the command to start a MongoDB instance in a development environment?

a) mongod --dev

b) mongod --dbpath <path>

c) mongo start

d) node start

Which tool can be used to manage multiple versions of Node.js in a project?

a) npm

b) Node Version Manager (NVM)

c) Yarn

d) Express

Which of the following is a recommended way to manage state in a React application?

a) React Context API

b) Redux

c) useState and useEffect


d) All of the above

How do you handle server-side validation in a MERN stack?

a) Using Mongoose validation

b) Using custom middleware in Express

c) Using React forms

d) Both a and b

You might also like