A simple RESTful Todo API built with TypeScript and Express. This application provides endpoints for creating, reading, updating, and deleting Todo items. For simplicity, it uses an in-memory store (an array) to keep track of todos.
This project is a minimal Todo API written in a single TypeScript file (app.ts
). It uses Express for handling HTTP requests, body-parser for parsing JSON request bodies, and uuid for generating unique identifiers. The API supports full CRUD (Create, Read, Update, Delete) operations on Todo items.
todo-api/
├── app.ts # Main application file with the full API implementation
├── package.json # Project metadata and dependencies
├── tsconfig.json # TypeScript compiler configuration
└── .gitignore # Files/folders to ignore in Git
Clone the Repository
git clone https://github.com/your-username/todo-api.git
cd todo-api
Install Dependencies
Make sure you have Node.js installed. Then run:
npm install
This project uses default settings and does not require additional configuration. The server runs on port 3000 by default. You can change the port by setting the PORT
environment variable.
For development, you can use ts-node
to run the app without compiling:
npm start
This will start the server on http://localhost:3000.
The following endpoints are available:
/todos
[
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"title": "Buy groceries",
"completed": false
}
]
/todos/:id
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"title": "Buy groceries",
"completed": false
}
/todos
{
"title": "Buy groceries"
}
Response:
{
"id": "newly-generated-uuid",
"title": "Buy groceries",
"completed": false
}
/todos/:id
{
"title": "Buy groceries and cook dinner",
"completed": true
}
Response:
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"title": "Buy groceries and cook dinner",
"completed": true
}
/todos/:id
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"title": "Buy groceries and cook dinner",
"completed": true
}
For local development, use ts-node
to run the TypeScript application without compiling:
npm start
If you prefer compiling to JavaScript, run:
npm run build
Then execute the compiled JavaScript from the dist
folder:
node dist/app.js
Build:
The command npm run build
uses the TypeScript compiler (tsc
) to compile the source code into the dist
directory.
Deployment:
To deploy the app, compile it with npm run build
and deploy the contents of the dist
folder to your Node.js hosting environment. Ensure that you set the environment variable PORT
if you need a custom port.
You can use tools like Postman or curl
to test the API endpoints. Automated testing can be added using frameworks such as Mocha or Jest if required.
Server Not Starting:
Ensure that all dependencies are installed and that you are running the correct Node.js version.
Endpoint Not Found:
Double-check the URL and port number. Ensure the server is running on the expected port.
TypeScript Errors:
Review the error messages and adjust your code or tsconfig.json
settings accordingly.
Contributions are welcome! To contribute:
git checkout -b feature/my-new-feature
).This project is licensed under the MIT License. See the LICENSE file for details.
Enjoy using the Todo API, and feel free to extend it with persistent storage, authentication, and more advanced features!