Learn Node Js MCQs

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

What is the default port number for the HTTP server in Node.js?

1) 3000

2) 8080

3) 80

4) 443

Answer : Option 1

How do you create a new server in Node.js?

1) http.createServer()

2) server.create()

3) http.newServer()

4) server.create()

Answer : Option 1

Which module is used for working with file systems in Node.js?

1) fs

2) http

3) path

4) os

Answer : Option 1

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

1) Provides information about the current process

2) Handles HTTP requests

3) Manages server connections

4) Reads files

Answer : Option 1

How do you install a global package in Node.js?

1) npm install -g <package>

2) npm install <package> -g

3) npm global install <package>

4) node install <package>

Answer : Option 1

What method would you use to handle errors in asynchronous code?

1) Try/catch blocks

2) Error callback

3) Promise.catch()

4) Both B and C

Answer : Option 4

Which module provides utilities for working with file and directory paths?

1) path

2) fs

3) url

4) http

Answer : Option 1

How do you handle HTTP POST requests in Express.js?

1) app.post()

2) app.get()

3) app.request()

4) app.handle()

Answer : Option 1

What is the use of `npm run` in Node.js?

1) To run scripts defined in package.json

2) To install packages

3) To start the server

4) To debug code

Answer : Option 1

Which function is used to read environment variables in Node.js?

1) process.env

2) config.get()

3) env.read()

4) config.read()

Answer : Option 1