A Node.js/Express application that manages tasks using a MySQL database (via Sequelize). It also supports webhooks that notify external endpoints when tasks are created or updated.
- Overview
- Installation
- Environment Variables
- Running the App
- API Endpoints
- Testing with cURL
- Webhook Example
This app provides a Task Manager API with CRUD endpoints:
- Create a task
- Read (all tasks or by ID)
- Update a task
- Delete a task
It also includes a webhook feature. You can subscribe an external URL to be notified when tasks are created/updated.
- Clone this repo or copy the code to your local machine.
- Install dependencies:
npm install
- Set up MySQL on your server (A2 Hosting or local). Make sure you have a database for this project.
Create a .env
file in the project root (or set variables in cPanel). For example:
DB_HOST=localhost
DB_PORT=3306
DB_USER=<your_db_user>
DB_PASSWORD=<your_db_password>
DB_NAME=<your_db_name>
APP_PORT=3000
- Run locally:
or
node app.js
npm start
- On A2 Hosting, ensure the
.htaccess
passenger config is set correctly, then restart your Node.js app in cPanel.
GET /tasks
– Retrieve all tasks.GET /tasks/:id
– Retrieve a single task by ID.POST /tasks
– Create a new task.PUT /tasks/:id
– Update a task by ID.DELETE /tasks/:id
– Delete a task by ID.GET /webhooks
– List all webhook subscriptions.POST /webhooks
– Subscribe to a webhook event (task.created
ortask.updated
).DELETE /webhooks/:id
– Remove a webhook subscription.
You can verify routes without a GUI tool by running cURL commands in a terminal or SSH session.
Assume you have a route like GET https://cuureo.com/tasks
:
curl -i https://cuureo.com/tasks
-i
shows the response headers plus the body.- You should see something like:
HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 ... [ { "id": 1, "title": "Some Task", ... }, ... ]
- If your route responds with JSON, you’ll see the returned data in the terminal.
For something like GET https://cuureo.com/tasks/1
:
curl -i https://cuureo.com/tasks/1
- This tests retrieving a single resource with ID = 1.
- If the item doesn’t exist, you might get a 404 Not Found.
To create a new resource (e.g., create a new task), you often send a JSON body. Example:
curl -i -X POST https://cuureo.com/tasks \
-H "Content-Type: application/json" \
-d '{"title":"New Task from cURL2","description":"Testing POST","status":"new"}'
Explanation:
-X POST
sets the HTTP method to POST.-H "Content-Type: application/json"
indicates you’re sending JSON.-d '{...}'
is the JSON data you’re posting.
If successful, you might see a 201 Created response, plus the JSON of the newly created resource.
To update a task with ID = 2, for example:
curl -i -X PUT https://cuureo.com/tasks/2 \
-H "Content-Type: application/json" \
-d '{"title":"Updated Task Title","status":"in-progress"}'
- This sends new data to
/tasks/2
. - Expect a 200 OK if the update succeeds (or 404 Not Found if the task doesn’t exist).
To delete a task by ID, e.g., ID = 3:
curl -i -X DELETE https://cuureo.com/tasks/3
- If it’s deleted, you might see:
HTTP/1.1 200 OK { "message": "Task deleted" }
-
Check Response Codes
- 200 OK or 201 Created means success.
- 404 Not Found could mean the resource or route doesn’t exist.
- 500 Internal Server Error indicates a server-side issue or unhandled exception.
-
Add
-v
for Verbose Modecurl -v https://cuureo.com/tasks
Shows request/response headers and can help debug SSL or redirect issues.
-
JSON Validation
- If your API expects JSON, always include
-H "Content-Type: application/json"
when sending a body. - Malformed JSON can result in a 400 Bad Request or 500 Internal Server Error, depending on your server code.
- If your API expects JSON, always include
-
Check Server Logs
- If you get unexpected responses, see if cPanel or Passenger logs show any error messages.
In Summary
Use cURL commands in your terminal or SSH session to hit each endpoint at your live domain. Confirm status codes and responses match what you expect. This is a quick way to verify your existing routes are set up correctly without needing a GUI tool like Postman. Once you see the expected responses (e.g., JSON output, success messages), you’ll know your Node.js/Express routes are functioning correctly in production.
To subscribe a webhook that listens for task.created
events, you can run:
curl -X POST https://cuureo.com/webhooks \
-H "Content-Type: application/json" \
-d '{"url":"https://webhook.site/4d5e143c-a50a-4f0d-8d8e-73c943a2a430","eventType":"task.created"}'
- This registers a new webhook for
task.created
. - The
url
(https://webhook.site/...
) is where your system will send a POST request whenever a new task is created. - When you create a task (via
POST /tasks
), your app will POST a payload like:to the specified{ "event": "task.created", "data": { "id": 123, "title": "New Task", "status": "new", ... } }
url
.