This is a simple Todo backend built using Express.js and MySQL. It provides basic functionality for user authentication, task management, and status updates.
-
Clone the Repository:
git clone https://github.com/your-username/your-repository-name.git cd your-repository-name -
Install Dependencies:
Ensure you have Node.js and npm installed. Then run:
npm install
-
Start the MySQL Server:
Make sure your MySQL server is running and accessible with the credentials provided in
index.js. -
Run the Server:
npm start
The server will start and listen on port 3000.
-
POST /login
- Description: Authenticate a user.
- Request Body:
{ "username": "your_username", "password": "your_password" } - Responses:
- 200 OK: Successful login
- 401 Unauthorized: Failed to login
-
POST /signup
- Description: Register a new user.
- Request Body:
{ "name": "your_name", "username": "your_username", "password": "your_password" } - Responses:
- 200 OK: Registered successfully
- 401 Unauthorized: Failed to register
-
POST /createtask
- Description: Create a new task.
- Request Body:
{ "taskname": "Task Name", "task_id": 1, "description": "Task Description" } - Responses:
- 200 OK: Created task successfully
- 401 Unauthorized: Failed to create task
-
POST /deletetask
- Description: Delete a task by ID.
- Request Body:
{ "task_id": 1 } - Responses:
- 200 OK: Deleted task successfully
- 401 Unauthorized: Failed to delete task
-
POST /changestatus
- Description: Change the status of a task.
- Request Body:
{ "task_id": 1, "done": "true" // or "false" } - Responses:
- 200 OK: Changed status successfully
- 400 Bad Request: Invalid status value
- 401 Unauthorized: Failed to change status
-
POST /getdata
- Description: Retrieve a task by ID.
- Request Body:
{ "task_id": 1 } - Responses:
- 200 OK: Returns task details
- 404 Not Found: Task not found
-
Create Database:
Create a database named
todoin your MySQL server. -
Create Tables:
Execute the following SQL commands to create the required tables:
CREATE TABLE login ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, username VARCHAR(255) UNIQUE NOT NULL, password VARCHAR(255) NOT NULL ); CREATE TABLE task ( task_id INT PRIMARY KEY, taskname VARCHAR(255) NOT NULL, description TEXT, done BOOLEAN NOT NULL DEFAULT false );
- Ensure that the MySQL credentials (
host,user,password,database) inindex.jsmatch your local MySQL setup. - Modify the CORS settings and error handling as per your project's requirements.
Replace the placeholder values with your actual repository details and adjust as needed.