A task management system that lets you switch between two ways of storing data: a real database (PostgreSQL) or a simple file (JSON). Built with Node.js and TypeScript.
- Switch storage easily - Use a database or a simple file
- Full task operations - Create, read, update, delete tasks
- Type safety - Built with TypeScript to catch errors early
- Automatic data loading - Start with sample tasks if using npm run seed if needed
npm installCreate a file called .env in the project folder:
Option A: Use PostgreSQL (recommended for real use)
PORT=3000
DATASOURCE=postgres
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=yourpassword
DB_NAME=tasks_dbOption B: Use simple file storage (good for testing)
PORT=3000
DATASOURCE=jsonnpm startYour API will be ready at: http://localhost:3000
GET http://localhost:3000/tasksGET http://localhost:3000/tasks/1POST http://localhost:3000/tasks
Content-Type: application/json
{
"userId": 1,
"title": "Buy groceries",
"completed": false
}PUT http://localhost:3000/tasks/1
Content-Type: application/json
{
"title": "Buy groceries and cook dinner",
"completed": true
}DELETE http://localhost:3000/tasks/1If you chose PostgreSQL:
createdb tasks_dbnpm run migratenpm run seedThis adds 10 sample tasks to get you started
- Good for multiple users
- Data stays safe
- Can handle lots of tasks
- Set
DATASOURCE=postgresin.env
- Simple to set up
- No database needed
- Good for testing
- Set
DATASOURCE=jsonin.env - Tasks are saved in
data/tasks.json
src/
├── controllers/ # Handles web requests
├── services/ # Business logic
├── repositories/ # Saves/reads data
├── models/ # Data types
├── data/ # JSON file storage
├── migrations/ # Database setup
└── seeds/ # Sample data
# Run in development mode
npm run dev
# Build the project
npm run build
# Run tests
npm test
# Reset database
npm run migrate:rollback
npm run migrate- Choose one storage option - Your
.envfile decides if you use database or file - Data doesn't sync - Tasks in database won't automatically appear in JSON file
- Start with sample data - Use
npm run seedto get sample tasks - Switch anytime - Change
.envand restart to switch storage
Check if:
- Your
.envfile is in the right place - PostgreSQL is running (if using database)
- The port 3000 is free
- You've run
npm installfirst
The API is now ready at http://localhost:3000