Learn Node Js MCQs
Prepare Node Js MCQs (Multiple choice Questions) for exam and job interviews.
What is the purpose of `process.nextTick()`?
1) To execute a function on the next iteration of the event loop
2) To handle synchronous code
3) To parse incoming requests
4) To handle HTTP responses
Answer : Option 1
Which Node.js function reads the contents of a directory?
1) fs.readdir()
2) fs.readFile()
3) fs.open()
4) fs.createReadStream()
Answer : Option 1
What is the purpose of the `events` module in Node.js?
1) To handle and emit events
2) To parse URLs
3) To manage file systems
4) To handle HTTP requests
Answer : Option 1
How do you handle errors in asynchronous code using Promises?
1) Using `.catch()` method
2) Using `try/catch` block
3) Using `process.nextTick()`
4) Using `async/await`
Answer : Option 1
What is the purpose of the `fs.createReadStream()` method?
1) To create a readable stream from a file
2) To create a writable stream to a file
3) To read the contents of a file
4) To write data to a file
Answer : Option 1
How do you perform input validation in Node.js?
1) Using validation libraries like Joi or express-validator
2) Using custom validation functions
3) Using regular expressions
4) All of the above
Answer : Option 4
Which module is used to parse URL query strings in Node.js?
1) querystring
2) url
3) path
4) fs
Answer : Option 1
What is the purpose of `npm install --save-dev`?
1) To install development dependencies
2) To install production dependencies
3) To install global packages
4) To update packages
Answer : Option 1
How do you create a new HTTP server in Node.js?
1) Using `http.createServer()`
2) Using `server.create()`
3) Using `http.newServer()`
4) Using `server.create()`
Answer : Option 1
What is the purpose of the `os` module in Node.js?
1) Provides operating system-related utility methods
2) Handles file system operations
3) Manages HTTP requests
4) Parses URLs
Answer : Option 1