Learn Node Js MCQs

Prepare Node Js MCQs (Multiple choice Questions) for exam and job interviews.

Which method is used to handle HTTP GET requests in Express.js?

1) app.get()

2) app.post()

3) app.put()

4) app.delete()

Answer : Option 1

What does the `fs.appendFile()` method do?

1) Appends data to a file

2) Creates a new file

3) Reads data from a file

4) Deletes a file

Answer : Option 1

How do you handle form submissions in Node.js?

1) Using `body-parser` middleware

2) Using `querystring` module

3) Using `fs` module

4) Using `url` module

Answer : Option 1

What is the role of the `callback` function in Node.js?

1) To handle asynchronous operations

2) To create synchronous code

3) To manage server connections

4) To read files

Answer : Option 1

Which method is used to stop the Node.js server?

1) server.close()

2) server.stop()

3) server.end()

4) server.quit()

Answer : Option 1

What does the `process.exit()` method do?

1) Terminates the Node.js process

2) Starts the Node.js process

3) Handles HTTP requests

4) Creates a new file

Answer : Option 1

Which function is used to parse incoming request bodies in Express.js?

1) body-parser()

2) express.json()

3) express.urlencoded()

4) req.body()

Answer : Option 2

What is a middleware function in Express.js?

1) A function that processes requests and responses

2) A function that handles HTTP errors

3) A function that starts the server

4) A function that handles file uploads

Answer : Option 1

How do you define a route in Express.js?

1) app.use()

2) app.route()

3) app.get()

4) app.define()

Answer : Option 3

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

1) http

2) request

3) response

4) server

Answer : Option 1