Learn Node Js MCQs
Prepare Node Js MCQs (Multiple choice Questions) for exam and job interviews.
How do you create an HTTP POST request in Node.js?
1) Using `http.request()` with the method set to POST
2) Using `http.get()`
3) Using `http.createServer()`
4) Using `http.send()`
Answer : Option 1
Which method is used to resolve a URL path in Node.js?
1) url.resolve()
2) url.format()
3) url.parse()
4) url.searchParams()
Answer : Option 1
What is the purpose of `cluster.fork()`?
1) To create a new worker process
2) To terminate the current process
3) To create a new thread
4) To split a string into an array
Answer : Option 1
How can you get the current working directory in Node.js?
1) Using `process.cwd()`
2) Using `fs.cwd()`
3) Using `path.cwd()`
4) Using `os.cwd()`
Answer : Option 1
What does `os.type()` return?
1) The operating system name
2) The total memory of the system
3) The system’s CPU architecture
4) The system’s hostname
Answer : Option 1
Which core module in Node.js provides utilities for working with file and directory paths?
1) fs
2) url
3) path
4) http
Answer : Option 3
What does the `http.createServer()` method return?
1) A stream
2) An event emitter
3) An HTTP server instance
4) A TCP socket
Answer : Option 3
How can you read the contents of a directory asynchronously in Node.js?
1) fs.readFile()
2) fs.read()
3) fs.readdir()
4) fs.opendir()
Answer : Option 3
Which method is used to append data to a file in Node.js asynchronously?
1) fs.write()
2) fs.addFile()
3) fs.appendFile()
4) fs.insert()
Answer : Option 3
What is the purpose of the `querystring.parse()` method in Node.js?
1) Stringify query parameters
2) Resolve a URL
3) Parse a URL query string into an object
4) Format a URL
Answer : Option 3