Learn Node Js MCQs
Prepare Node Js MCQs (Multiple choice Questions) for exam and job interviews.
What module is used to handle file paths in Node.js?
1) fs
2) path
3) url
4) http
Answer : Option 2
Which method is used to read the contents of a directory asynchronously in Node.js?
1) fs.readdir()
2) fs.readFile()
3) fs.writeFile()
4) fs.unlink()
Answer : Option 1
What does the `process.uptime()` method return?
1) The system uptime in seconds
2) The Node.js process uptime in seconds
3) The CPU usage time
4) The total memory usage
Answer : Option 2
How do you stop a setInterval timer in Node.js?
1) Using `clearTimeout()`
2) Using `process.exit()`
3) Using `clearInterval()`
4) Using `setTimeout()`
Answer : Option 3
Which module in Node.js is used for handling streams?
1) events
2) stream
3) buffer
4) http
Answer : Option 2
How do you create a new file and write data to it in Node.js?
1) Using `fs.writeFile()`
2) Using `fs.appendFile()`
3) Using `fs.open()`
4) Using `fs.createWriteStream()`
Answer : Option 1
What is the purpose of `http.createServer()`?
1) To create an HTTP server
2) To create a file server
3) To create a TCP server
4) To create a UDP server
Answer : Option 1
How can you check if a path is a directory in Node.js?
1) Using `fs.stat()`
2) Using `fs.readdir()`
3) Using `fs.readFile()`
4) Using `fs.isDirectory()`
Answer : Option 1
Which module is used to work with URL parsing in Node.js?
1) path
2) url
3) querystring
4) http
Answer : Option 2
What is the purpose of the `querystring.stringify()` method?
1) To parse a URL string into an object
2) To convert an object into a URL query string
3) To resolve a URL path
4) To format a URL string
Answer : Option 2