Learn Node Js MCQs

Prepare Node Js MCQs (Multiple choice Questions) for exam and job interviews.

How do you manage dependencies in a Node.js project?

1) Using `package.json` and `npm`

2) Using `requirements.txt`

3) Using `dependencies` file

4) Using `project.json`

Answer : Option 1

What is the purpose of the `express.json()` middleware?

1) To parse incoming JSON request bodies

2) To handle file uploads

3) To parse URL-encoded data

4) To manage sessions

Answer : Option 1

Which function is used to get environment variables in Node.js?

1) process.env

2) config.get()

3) env.read()

4) config.read()

Answer : Option 1

How do you handle file streams in Node.js?

1) Using `fs.createReadStream()` and `fs.createWriteStream()`

2) Using `fs.readFile()` and `fs.writeFile()`

3) Using `fs.open()` and `fs.close()`

4) Using `fs.appendFile()` and `fs.unlink()`

Answer : Option 1

What is the `app.use()` method used for in Express.js?

1) To add middleware to the application

2) To define routes

3) To start the server

4) To handle errors

Answer : Option 1

Which function is used to check if a file exists in Node.js?

1) fs.access()

2) fs.exists()

3) fs.check()

4) fs.fileExists()

Answer : Option 1

What is the `async` keyword used for in Node.js?

1) To declare asynchronous functions

2) To handle synchronous code

3) To manage file systems

4) To parse JSON data

Answer : Option 1

How do you get the IP address of a client in an Express.js application?

1) Using `req.ip`

2) Using `req.address`

3) Using `req.clientIp`

4) Using `req.remoteAddress`

Answer : Option 1

Which Node.js method is used to append data to a file?

1) fs.appendFile()

2) fs.writeFile()

3) fs.createWriteStream()

4) fs.append()

Answer : Option 1

What is the purpose of the `url` module in Node.js?

1) To parse and format URLs

2) To handle HTTP requests

3) To manage file paths

4) To work with streams

Answer : Option 1