Learn Node Js MCQs
Prepare Node Js MCQs (Multiple choice Questions) for exam and job interviews.
How do you set up a Node.js application to use HTTPS?
1) By configuring an HTTPS server with the `https` module
2) By using `http` module with SSL certificates
3) By using `express` module
4) By configuring middleware
Answer : Option 1
What does the `fs.readFile()` method do?
1) Reads a file synchronously
2) Reads a file asynchronously
3) Creates a readable stream
4) Opens a file
Answer : Option 2
How do you create a simple HTTP server in Node.js?
1) Using `http.request()`
2) Using `http.createServer()`
3) Using `http.get()`
4) Using `http.Server()`
Answer : Option 2
What is the purpose of the `Buffer` class in Node.js?
1) To manage file paths
2) To handle binary data
3) To create HTTP requests
4) To handle JSON data
Answer : Option 2
How do you handle large data streams in Node.js?
1) By using synchronous file operations
2) By using buffer modules
3) By using streams
4) By using HTTP requests
Answer : Option 3
What is the purpose of the `domain` module in Node.js?
1) To handle HTTP requests
2) To manage file systems
3) To work with streams
4) To manage error handling and context propagation
Answer : Option 4
How do you implement rate limiting in an Express.js application?
1) By using custom code
2) By limiting request payload size
3) By using middleware like `express-rate-limit`
4) By using session management
Answer : Option 3
How do you parse command-line arguments in Node.js?
1) Using `command-line` module
2) Using `cli-parser` module
3) Using `process.argv`
4) Using `args` module
Answer : Option 3
What is the purpose of the `fs.writeFile()` method?
1) To read data from a file
2) To create a writable stream
3) To delete a file
4) To write data to a file asynchronously
Answer : Option 4
How do you handle HTTP POST requests in Express.js?
1) Using `app.get()` method
2) Using `app.put()` method
3) Using `app.delete()` method
4) Using `app.post()` method
Answer : Option 4