Learn Node Js MCQs
Prepare Node Js MCQs (Multiple choice Questions) for exam and job interviews.
Which method is used to close a writable stream?
1) end()
2) finish()
3) close()
4) destroy()
Answer : Option 1
How do you determine the absolute path of a relative path in Node.js?
1) Using `path.resolve()`
2) Using `path.join()`
3) Using `path.parse()`
4) Using `path.basename()`
Answer : Option 1
What does `http.IncomingMessage` represent?
1) An incoming HTTP request
2) An outgoing HTTP response
3) A network connection
4) A file upload event
Answer : Option 1
How do you set a timeout for a specific function in Node.js?
1) Using `setTimeout()`
2) Using `setInterval()`
3) Using `clearTimeout()`
4) Using `process.nextTick()`
Answer : Option 1
Which module in Node.js is used for child processes?
1) child_process
2) process
3) cluster
4) os
Answer : Option 1
What does the `crypto.createHash()` method do?
1) Creates a hash object that can be used to generate hash digests
2) Encrypts data using a specified algorithm
3) Decrypts data using a specified key
4) Generates random bytes
Answer : Option 1
How do you format a string using placeholders in Node.js?
1) Using `util.format()`
2) Using `url.format()`
3) Using `path.format()`
4) Using `fs.format()`
Answer : Option 1
Which method is used to listen for the close event on a stream?
1) on('close')
2) on('data')
3) on('end')
4) on('error')
Answer : Option 1
What is the purpose of `path.basename()`?
1) To get the last portion of a path
2) To join multiple path segments
3) To resolve a path to an absolute path
4) To normalize a path
Answer : Option 1
How can you write data to a writable stream in Node.js?
1) Using `.write()` method
2) Using `.read()` method
3) Using `.end()` method
4) Using `.pipe()` method
Answer : Option 1