### Instruction:
Develop a Node.js application that connects to a MongoDB database and allows users to create, read, update, and delete records for a simple "to-do" list.


### Response:

To create a simple "to-do" list application using Node.js and MongoDB, follow these steps:

1. Install required dependencies

First, make sure you have Node.js installed on your system. You can download it from https://nodejs.org/.

Next, create a new directory for your project and navigate to it in the terminal.

Run the following command to initialize a new Node.js project:

```
npm init -y
```

Now, install the necessary dependencies:

- Express: A web framework for Node.js.
- Mongoose: An Object Data Modeling (ODM) library for MongoDB and Node.js.
- Body-parser: Middleware to parse incoming request bodies.

Install them by running:

```
npm install express mongoose body-parser
```

2. Set up the server

Create a new file called `app.js` in your project folder and add the following code:

```javascript
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');

const app = express();

// Connect to MongoDB
mongoose.connect('mongodb://localhost/todo', { useNewUrlParser: true, useUnifiedTopology: true });

// Use body-parser middleware
app.use(bodyParser.json());

// Import routes
const todoRoutes = require('./routes/todo');
app.use('/todos', todoRoutes);

// Start the server
const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});
```

3. Create the schema and model

In your project folder, create a new folder called `models`. Inside this folder, create a new file called `todo.js` with the following content:

```javascript
const mongoose = require('mongoose');

const TodoSchema = new mongoose.Schema({
  title: {
    type: String,
    required: true
  },
  completed: {
    type: Boolean,
    default: false
  },
  createdAt: {
    type: Date,
    default: Date.now
  }
});

module.exports = mongoose.model('Todo', TodoSchema);
```

4. Create the routes

In your project folder, create a new folder called `routes`. Inside this folder, create a new file called `todo.js` with the following content:

```javascript
const express = require('express');
const router = express.Router();
const Todo = require('../models/todo');

// Get all todos
router.get('/', async (req, res) => {
  try {
    const todos = await Todo.find();
    res.json(todos);
  } catch (err) {
    res.status(500).json({ message: err.message });
  }
});

// Add a todo
router.post('/', async (req, res) => {
  const todo = new Todo({
    title: req.body.title
  });

  try {
    const newTodo = await todo.save();
    res.status(201).json(newTodo);
  } catch (err) {
    res.status(400).json({ message: err.message });
  }
});

// Update a todo
router.patch('/:id', getTodo, async (req, res) => {
  if (req.body.title != null) {
    res.todo.title = req.body.title;
  }

  if (req.body.completed != null) {
    res.todo.completed = req.body.completed;
  }

  try {
    const updatedTodo = await res.todo.save();
    res.json(updatedTodo);
  } catch (err) {
    res.status(400).json({ message: err.message });
  }
});

// Delete a todo
router.delete('/:id', getTodo, async (req, res) => {
  try {
    await res.todo.remove();
    res.json({ message: 'Deleted Todo' });
  } catch (err) {
    res.status(500).json({ message: err.message });
  }
});

// Middleware to get a todo by ID
async function getTodo(req, res, next) {
  let todo;
  try {
    todo = await Todo.findById(req.params.id);
    if (todo == null) {
      return res.status(404).json({ message: 'Cannot find todo' });
    }
  } catch (err) {
    return res.status(500).json({ message: err.message });
  }

  res.todo = todo;
  next();
}

module.exports = router;
```

5. Run the application

Make sure you have MongoDB installed and running on your system.

Start your Node.js server by running:

```
node app.js
```

Now, you can use tools like Postman or curl to test your API endpoints for creating, reading, updating, and deleting "to-do" list items.

For example, to create a new "to-do" item, send a POST request with JSON data to `http://localhost:3000/todos`:

```json
{
  "title": "Buy groceries"
}
```

To fetch all "to-do" items, send a GET request to `http://localhost:3000/todos`.

To update an existing "to-do" item, send a PATCH request with JSON data to `http://localhost:3000/todos/:id`, where `:id` is the ID of the item:

```json
{
  "completed": true
}
```

To delete a "to-do" item, send a DELETE request to `http://localhost:3000/todos/:id`, where `:id` is the ID of the item.