Learn Node Js MCQs

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

What does `os.arch()` method return?

1) The operating system’s CPU architecture

2) The operating system’s release version

3) The system’s hostname

4) The system’s total memory

Answer : Option 1

How do you check if a file exists in Node.js?

1) Using `fs.existsSync()`

2) Using `fs.readFile()`

3) Using `fs.writeFile()`

4) Using `fs.mkdirSync()`

Answer : Option 1

What is the purpose of the `util.format()` method?

1) To format a string using placeholders

2) To inherit prototype methods

3) To create a buffer from a string

4) To parse a URL string

Answer : Option 1

How do you create a directory synchronously in Node.js?

1) Using `fs.mkdirSync()`

2) Using `fs.mkdir()`

3) Using `fs.rmdirSync()`

4) Using `fs.readdirSync()`

Answer : Option 1

What does the `process.hrtime()` method return?

1) The current high-resolution real time

2) The process ID

3) The current working directory

4) The system’s uptime

Answer : Option 1

How do you make an HTTP POST request in Node.js?

1) Using `http.request()` with method set to POST

2) Using `http.get()`

3) Using `http.createServer()`

4) Using `http.fetch()`

Answer : Option 1

What does `os.cpus()` return?

1) An array of objects containing information about each CPU/core

2) The total memory of the system

3) The system’s hostname

4) The system’s architecture

Answer : Option 1

How do you handle unhandled promise rejections?

1) By using `process.on('unhandledRejection', ...)`

2) By using `process.on('rejectionHandled', ...)`

3) By using `process.exit()`

4) By using `process.nextTick()`

Answer : Option 1

What is the purpose of the `http.STATUS_CODES` object?

1) To provide a mapping of HTTP status codes to status messages

2) To provide a list of HTTP request methods

3) To provide a list of HTTP header fields

4) To provide a list of HTTP response types

Answer : Option 1

How do you parse a URL in Node.js?

1) Using `url.parse()`

2) Using `url.format()`

3) Using `url.resolve()`

4) Using `url.searchParams()`

Answer : Option 1