Build a complete Task Manager API from scratch, applying everything you have learned about Node.js, Express, Sequelize, and Authentication.
Models define your database tables. Our Task Manager has two models: User and Task.
Routes define the URL endpoints your API responds to. They map HTTP methods to controller functions.
router.use(authenticate) protects ALL task routes at once. Every request to /api/tasks/* must include a valid JWT token.
Controllers handle the HTTP request and response. They receive data from the client, call the service layer, and send back a response.
Services contain the business logic. They interact with models and handle data processing, keeping controllers thin and focused on HTTP concerns.
You can test your API using curl commands in the terminal, or use a tool like Postman or Thunder Client.
"dev": "nodemon server.js" to the "scripts" section of your package.json. Then npm run dev will auto-restart the server whenever you save a file.
| Method | Endpoint | Auth? | Description |
|---|---|---|---|
| POST | /api/auth/register | No | Create new user |
| POST | /api/auth/login | No | Login, get token |
| GET | /api/tasks | Yes | List all user's tasks |
| GET | /api/tasks/:id | Yes | Get one task |
| POST | /api/tasks | Yes | Create a task |
| PUT | /api/tasks/:id | Yes | Update a task |
| DELETE | /api/tasks/:id | Yes | Delete a task |
1. Where does business logic belong in this architecture?
2. How do we protect all task routes at once?
3. What is the controller's main responsibility?
4. Why does the task service filter by UserId?
5. What does sequelize.sync() do when the server starts?