Learn Node Js MCQs
Prepare Node Js MCQs (Multiple choice Questions) for exam and job interviews.
How do you handle uncaught exceptions in Node.js?
1) Using `process.on('uncaughtException', callback)`
2) Using `try/catch` blocks
3) Using error middleware
4) Using `domain` module
Answer : Option 1
What is the purpose of the `express.static()` middleware?
1) To serve static files
2) To parse JSON data
3) To handle form submissions
4) To manage sessions
Answer : Option 1
Which module is used to generate and manage unique IDs in Node.js?
1) uuid
2) crypto
3) random
4) idgen
Answer : Option 1
How do you handle multiple routes in Express.js?
1) Using `app.route()`
2) Using `app.use()`
3) Using `app.all()`
4) Using `app.get()` and `app.post()`
Answer : Option 2
What is the purpose of the `res.status()` method in Express.js?
1) To set the HTTP response status code
2) To send a response body
3) To redirect the client
4) To parse incoming data
Answer : Option 1
How do you execute asynchronous code sequentially in Node.js?
1) Using `async/await`
2) Using callback functions
3) Using Promises
4) Using `process.nextTick()`
Answer : Option 1
What does the `fs.rename()` method do?
1) Renames a file or directory
2) Deletes a file
3) Reads a file
4) Writes data to a file
Answer : Option 1
Which Node.js function is used to read a file asynchronously?
1) fs.readFile()
2) fs.open()
3) fs.createReadStream()
4) fs.readFileSync()
Answer : Option 1
How do you set response headers in Express.js?
1) Using `res.set()`
2) Using `res.headers()`
3) Using `res.header()`
4) Using `res.configure()`
Answer : Option 1
What does `npm install` do?
1) Installs dependencies listed in package.json
2) Updates dependencies
3) Uninstalls packages
4) Executes scripts
Answer : Option 1