Learn Node Js MCQs
Prepare Node Js MCQs (Multiple choice Questions) for exam and job interviews.
What does the `process.cwd()` method return?
1) The home directory of the current user
2) The root directory of the filesystem
3) The directory of the script file
4) The current working directory of the Node.js process
Answer : Option 4
How can you handle errors in asynchronous code?
1) Using `process.on("uncaughtException")`
2) By logging errors to the console
3) By ignoring them
4) Using try/catch with Promises or async/await
Answer : Option 4
What is the role of the `path` module in Node.js?
1) To make HTTP requests
2) To handle process events
3) To parse command-line arguments
4) To handle and transform file paths
Answer : Option 4
How do you make a Node.js application listen on a specific port?
1) By setting the `PORT` environment variable
2) By using the `http` module directly
3) By configuring a proxy server
4) Using the `listen()` method on a server object
Answer : Option 4
How do you access request headers in Express.js?
1) Using `req.query`
2) Using `req.params`
3) Using `req.body`
4) Using `req.headers`
Answer : Option 4
What does the `require()` function do in Node.js?
1) Creates new modules
2) Compiles JavaScript files
3) Handles HTTP requests
4) Loads and caches modules
Answer : Option 4
What is the purpose of the `cluster` module in Node.js?
1) To manage file system operations
2) To handle HTTP requests
3) To manage environment variables
4) To create child processes that share the same server port
Answer : Option 4
How do you handle uncaught exceptions in Node.js?
1) By using `try/catch` blocks
2) By using `domain` module
3) By ignoring them
4) By using `process.on("uncaughtException")`
Answer : Option 4
What is the purpose of the `debug` module in Node.js?
1) To handle file operations
2) To manage HTTP requests
3) To create child processes
4) To enable debugging and logging
Answer : Option 4
How do you use `setTimeout()` in Node.js?
1) To repeat a function at regular intervals
2) To pause code execution
3) To handle asynchronous operations
4) To execute a function after a specified delay
Answer : Option 4