To-Do List Project with Backend API

Step Description
1.1 Set Up Your Backend with Express.js
Initialize a New Node.js Project
mkdir todo-backend
cd todo-backend
npm init -y
This will create a package.json file with the default settings.
1.2 Install Required Packages
npm install express
Optionally, install nodemon for automatic server restarts during development:
npm install --save-dev nodemon
Add a script in your package.json to use nodemon:
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
}
1.3 Create a Basic Express Server
Create a new file called index.js:
touch index.js
Set up a basic Express server in index.js:
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;

app.use(express.json());

app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
Run your server:
npm run dev
2.1 Create an In-Memory Data Store
let todos = [];
2.2 Set Up CRUD Routes
Create a New To-Do Item (POST):
app.post('/todos', (req, res) => {
const todo = req.body;
todo.id = Date.now().toString();
todos.push(todo);
res.status(201).json(todo);
});