Learn Node Js MCQs
Prepare Node Js MCQs (Multiple choice Questions) for exam and job interviews.
How do you handle multiple asynchronous operations in Node.js?
1) Using Promises or async/await
2) Using try/catch blocks
3) Using if/else statements
4) Using process.nextTick()
Answer : Option 1
What does the `util.inspect()` method do?
1) Returns a string representation of an object for debugging
2) Creates a deep clone of an object
3) Merges two objects into one
4) Compares two objects for equality
Answer : Option 1
How can you create a buffer from a string in Node.js?
1) Using `Buffer.from()`
2) Using `Buffer.alloc()`
3) Using `Buffer.compare()`
4) Using `Buffer.concat()`
Answer : Option 1
What is the purpose of `tls.createServer()`?
1) To create a secure TCP server
2) To create a UDP server
3) To create an HTTP server
4) To create a WebSocket server
Answer : Option 1
How do you handle uncaught exceptions in a Node.js application?
1) Using `process.on('uncaughtException', ...)`
2) Using `try/catch` blocks
3) Using `throw` statements
4) Using `process.exit()`
Answer : Option 1
Which method is used to listen for data on a readable stream?
1) on('data')
2) on('end')
3) on('close')
4) on('error')
Answer : Option 1
What does `os.platform()` return?
1) The operating system platform
2) The system's CPU architecture
3) The system's hostname
4) The total memory of the system
Answer : Option 1
How do you delete a file asynchronously in Node.js?
1) Using `fs.unlink()`
2) Using `fs.remove()`
3) Using `fs.delete()`
4) Using `fs.destroy()`
Answer : Option 1
What is the purpose of `stream.pipe()`?
1) To pass data from a readable stream to a writable stream
2) To create a duplex stream
3) To create a transform stream
4) To close a stream
Answer : Option 1
How can you get the version of Node.js that you are running?
1) Using `node -v` or `process.version`
2) Using `node --version` or `fs.version()`
3) Using `node -version` or `process.env.NODE_VERSION`
4) Using `node.version` or `process.getVersion()`
Answer : Option 1