Skip to content

Minimal Task Manager REST API built with Node.js, Express, and MongoDB (Mongoose). CRUD tasks with JSON and CORS.

Notifications You must be signed in to change notification settings

sanjayrohith/task-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Manager API

A minimal REST API for managing tasks, built with Node.js, Express, and MongoDB (Mongoose).

Features

  • Create, read, update, and delete tasks (CRUD)
  • JSON request/response
  • CORS enabled
  • Environment-based MongoDB connection via MONGO_URI

Tech Stack

  • Node.js + Express (ES Modules)
  • MongoDB + Mongoose
  • dotenv, cors, nodemon (dev)

Project Structure

task-manager/
├─ server.js               # App entrypoint, Express + routes + DB
├─ package.json            # Scripts and deps
├─ models/
│  └─ Task.js              # Mongoose Task model
├─ routes/
│  └─ taskRoutes.js        # CRUD routes for /api/tasks
└─ README.md

Getting Started

Prerequisites

  • Node.js 18+ (recommended)
  • MongoDB instance (local or hosted)

Installation

  1. Install dependencies
npm install
  1. Configure environment

Create a .env file in the project root with your Mongo connection string:

MONGO_URI=mongodb://localhost:27017/task_manager
  1. Run the server
  • Development (auto-reload):
npm run dev
  • Production:
npm start

The API listens on http://localhost:5000

API Reference

Base URL: http://localhost:5000/api/tasks

Data Model

Task

  • title (string, required)
  • description (string, optional)
  • status (string, default: "pending")

Example document:

{
	"_id": "6738a5f0f1c2a6f5a3d1e999",
	"title": "Write docs",
	"description": "Create README with API examples",
	"status": "pending"
}

Create a task

POST /api/tasks

Request

curl -X POST http://localhost:5000/api/tasks \
	-H 'Content-Type: application/json' \
	-d '{
		"title": "Write docs",
		"description": "Create README with API examples"
	}'

Response 201

{
	"_id": "...",
	"title": "Write docs",
	"description": "Create README with API examples",
	"status": "pending"
}

List tasks

GET /api/tasks

curl http://localhost:5000/api/tasks

Response 200

[
	{
		"_id": "...",
		"title": "Write docs",
		"description": "Create README with API examples",
		"status": "pending"
	}
]

Update a task

PUT /api/tasks/:id

curl -X PUT http://localhost:5000/api/tasks/<TASK_ID> \
	-H 'Content-Type: application/json' \
	-d '{
		"status": "done"
	}'

Response 200

{
	"_id": "...",
	"title": "Write docs",
	"description": "Create README with API examples",
	"status": "done"
}

Delete a task

DELETE /api/tasks/:id

curl -X DELETE http://localhost:5000/api/tasks/<TASK_ID>

Response 200

{ "message": "Task deleted" }

Error format

On validation or other errors, the API returns:

{ "error": "<message>" }

Scripts

  • npm run dev — start with nodemon (reload on changes)
  • npm start — start server

Notes & Tips

  • Ensure MONGO_URI is reachable from your machine/container.
  • The server currently binds to port 5000. Adjust in server.js if needed.

Roadmap / Ideas

  • Input validation (e.g., zod or express-validator)
  • Pagination and filtering for GET /api/tasks
  • Timestamps on tasks (createdAt, updatedAt)
  • Dockerfile and Compose for local Mongo + API
  • Tests (Jest + Supertest) and CI workflow
  • Authentication (JWT) and per-user tasks

License

ISC — see package.json.

About

Minimal Task Manager REST API built with Node.js, Express, and MongoDB (Mongoose). CRUD tasks with JSON and CORS.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published