Learn Node Js MCQs
Prepare Node Js MCQs (Multiple choice Questions) for exam and job interviews.
How do you handle file uploads in Node.js?
1) Using middleware like multer
2) Using custom code
3) Using the `fs` module
4) Using the `http` module
Answer : Option 1
Which method is used to set response headers in Express.js?
1) res.set()
2) res.headers()
3) res.header()
4) res.configure()
Answer : Option 1
What does the `fs.unlink()` method do?
1) Deletes a file
2) Renames a file
3) Reads a file
4) Writes data to a file
Answer : Option 1
What is the purpose of the `dotenv` package?
1) To manage environment variables
2) To handle HTTP requests
3) To parse JSON data
4) To validate inputs
Answer : Option 1
Which method is used to get query parameters in Express.js?
1) req.query
2) req.body
3) req.params
4) req.headers
Answer : Option 1
How do you create a readable stream from a file in Node.js?
1) Using `fs.createReadStream()`
2) Using `fs.readFile()`
3) Using `fs.open()`
4) Using `fs.createWriteStream()`
Answer : Option 1
What does the `process.env` object contain?
1) Environment variables
2) Process arguments
3) Server configurations
4) Application logs
Answer : Option 1
How do you create a writeable stream to a file in Node.js?
1) Using `fs.createWriteStream()`
2) Using `fs.writeFile()`
3) Using `fs.appendFile()`
4) Using `fs.open()`
Answer : Option 1
Which module is used for working with HTTP requests in Node.js?
1) http
2) express
3) request
4) url
Answer : Option 1
What is the purpose of `npm audit`?
1) To find and fix vulnerabilities in dependencies
2) To install packages
3) To update packages
4) To start a new project
Answer : Option 1