This project is a simple Todo REST API built using Node.js core modules (http and url) without any external frameworks like Express. It demonstrates basic CRUD operations (Create, Read, Update, Delete) for managing todo items in memory.
- List all todos
- Get a specific todo by ID
- Add a new todo
- Update an existing todo
- Delete a todo
-
Clone this repository or copy the project files.
-
Navigate to the project directory:
-
Install dependencies (if any):
npm install
-
Create a
.envfile in the project root and set the port:PORT=5000
npm run buildThe server will start and listen on the port specified in your .env file.
- GET
/todos - Response: Array of todo objects
- GET
/todos/:id - Response: Single todo object
- POST
/todos - Body: JSON
{ "text": "Task description", "completed": false } - Response: The created todo object
- PUT
/todos/:id - Body: JSON (fields to update, e.g.
{ "text": "New text", "completed": true }) - Response: The updated todo object
- DELETE
/todos/:id - Response:
{ success: true, data: {} }
- Todos are stored in memory; data will reset when the server restarts.
- Make sure to send valid JSON in the request body for POST and PUT requests.
- The server returns appropriate error messages for invalid requests.
Add a todo:
curl -X POST http://localhost:5000/todos \
-H "Content-Type: application/json" \
-d '{"text":"Buy groceries"}'Get all todos:
curl http://localhost:5000/todosUpdate a todo:
curl -X PUT http://localhost:5000/todos/1 \
-H "Content-Type: application/json" \
-d '{"completed":true}'Delete a todo:
curl -X DELETE http://localhost:5000/todos/1Feel free to modify and extend this project for your learning or prototyping needs!