Backend Interview Questions
Backend Interview Questions
**
Node.js is an open-source, cross-platform JavaScript runtime environment that
allows developers to execute JavaScript code outside of a web browser. It is built
on Chrome's V8 JavaScript engine and provides an event-driven, non-blocking I/O
model that makes it lightweight and efficient.
3. **What is I/O?**
I/O stands for Input/Output. In the context of Node.js, I/O refers to reading
from or writing to external resources like files, network sockets, or databases.
18. **How to create a simple server in Node.js that returns "Hello, World"?**
Here's an example of creating a simple server in Node.js that returns "Hello,
World" for all incoming requests:
```javascript
const http = require('http');
server.listen(3000, () => {
console.log('Server is listening on port 3000');
});
```
```javascript
const express = require('express');
const mongoose = require('mongoose');
// Connect to MongoDB
mongoose.connect('mongodb://localhost/mydatabase', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
// Example route
app.get('/users', async (req, res) => {
const users = await User.find();
res.json(users);
});