A REST API for managing tasks with user authentication, built with Node.js, Express, and SQLite.
- User registration and authentication
- JWT-based authentication
- CRUD operations for tasks
- User-specific task management
- SQLite database with Sequelize ORM
POST /api/register- Register a new userPOST /api/login- Login user
GET /api/tasks- Get all tasks for authenticated userGET /api/tasks/:id- Get single taskPOST /api/tasks- Create new taskPUT /api/tasks/:id- Update taskDELETE /api/tasks/:id- Delete task
GET /health- Health check endpointGET /- API information
- Install dependencies:
npm install
- Seed the database (optional):
npm run seed
- Start the server:
npm start `` - The API will be available at
http://localhost:3000
If you run the seed script, you'll have these test users available:
- john@example.com / password123 (3 tasks)
- jane@example.com / password123 (3 tasks)
- mike@example.com / password123 (4 tasks)
You can use these accounts to test the API without having to register new users.
Use the following sample requests to test the API:
Register a user:
POST /api/register
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com",
"password": "password123"
}Login:
POST /api/login
Content-Type: application/json
{
"email": "john@example.com",
"password": "password123"
}Create a task (requires authentication):
POST /api/tasks
Content-Type: application/json
Authorization: Bearer YOUR_JWT_TOKEN
{
"title": "Complete project",
"description": "Finish the task management API",
"priority": "high"
}This API uses SQLite for simplicity. The database file (tasks.db) will be created automatically when you start the server. Note for deployment: SQLite databases on platforms like Render will reset when containers restart. For persistent storage in production, consider upgrading to PostgreSQL.
NODE_ENV- Environment (development/production)PORT- Server port (default: 3000)JWT_SECRET- Secret key for JWT tokensJWT_EXPIRES_IN- JWT token expiration timeDB_NAME- Database file name
This API is ready to deploy to cloud platforms like Render. Make sure to:
- Set appropriate environment variables
- Use a secure JWT secret in production
- Consider database limitations with SQLite