Learn Node Js MCQs
Prepare Node Js MCQs (Multiple choice Questions) for exam and job interviews.
What is the `crypto` module used for in Node.js?
1) To handle HTTP requests
2) To manage file systems
3) To parse URLs
4) To provide cryptographic functionality
Answer : Option 4
How do you create a new module in Node.js?
1) By using the `require()` function
2) By defining global variables
3) By creating new classes
4) By exporting functions or objects using `module.exports`
Answer : Option 4
What does the `process.env` object contain?
1) Command-line arguments
2) File system information
3) HTTP request headers
4) Environment variables
Answer : Option 4
How do you handle promises in Node.js?
1) By using callbacks
2) By using synchronous code
3) By using `async/await`
4) By using `.then()` and `.catch()` methods
Answer : Option 1
What is the purpose of the `http` module in Node.js?
1) To manage file systems
2) To handle process events
3) To parse URLs
4) To create and handle HTTP servers and requests
Answer : Option 4
How do you handle file uploads in Express.js?
1) By using `req.files`
2) By using `fs` module
3) By using `formidable` package
4) By using middleware like `multer`
Answer : Option 4
What is the `Buffer` class used for in Node.js?
1) To manage file paths
2) To handle HTTP requests
3) To parse JSON data
4) To handle binary data
Answer : Option 4
How do you set up a basic Express.js server?
1) By creating an instance of `http.Server()`
2) By using `express.Router()`
3) By using `app.use()`
4) By creating an instance of `express()` and using `app.listen()`
Answer : Option 4
What does the `fs.appendFile()` method do?
1) Reads data from a file
2) Writes data to a file
3) Deletes a file
4) Appends data to a file
Answer : Option 4
How do you manage packages in Node.js?
1) By manually copying files
2) By creating new modules
3) By using `require()`
4) By using `npm` or `yarn`
Answer : Option 4