Learn Node Js MCQs

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

How do you create an HTTPS server in Node.js?

1) By using the `http` module

2) By using `tls` module only

3) By using `express` module

4) By using the `https` module with SSL/TLS certificates

Answer : Option 4

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

1) Deletes a file

2) Copies a file

3) Reads a file

4) Renames a file or directory

Answer : Option 4

How do you use the `fs.promises` API?

1) By using callback-based file operations

2) By using synchronous file operations

3) By using stream-based file operations

4) By using promise-based file system operations

Answer : Option 4

What is the purpose of the `process.stdout` object?

1) To handle input streams

2) To manage file systems

3) To parse URLs

4) To handle output streams

Answer : Option 4

How do you set up environment variables in Node.js?

1) By hardcoding values in code

2) By using `config` module

3) By setting system environment variables directly

4) Using `.env` files and `dotenv` package

Answer : Option 4

What is the role of the `events` module in Node.js?

1) To manage HTTP requests

2) To work with file systems

3) To parse URLs

4) To handle asynchronous events and event emitters

Answer : Option 4

How do you ensure that asynchronous code executes in order?

1) By using synchronous functions

2) By using `setImmediate()`

3) By chaining Promises or using async/await

4) By using callback functions

Answer : Option 3

What does the `path.extname()` method return?

1) The base name of a path

2) The directory name of a path

3) The full path

4) The extension of a path

Answer : Option 4

How do you use the `http` module to send HTTP responses?

1) By using `res.send()`

2) By using `res.json()`

3) By using `res.redirect()`

4) By using `res.write()` and `res.end()`

Answer : Option 4

What is the purpose of the `process.env` object?

1) To manage file systems

2) To handle HTTP requests

3) To parse URLs

4) To access environment variables

Answer : Option 4