Features β’ Tech Stack β’ Getting Started β’ API Docs β’ Structure
|
|
|
Runtime JavaScript runtime built on Chrome's V8 engine |
Framework Fast, minimalist web framework for Node.js |
Database NoSQL database with Mongoose ODM |
Language Typed superset of JavaScript |
| Package | Version | Purpose |
|---|---|---|
| express | 5.2.1 | Web application framework |
| mongoose | 9.2.0 | MongoDB object modeling |
| jsonwebtoken | 9.0.3 | JWT authentication |
| bcrypt | 6.0.0 | Password hashing |
| cors | 2.8.6 | Cross-origin resource sharing |
| helmet | 8.1.0 | Security HTTP headers |
| express-rate-limit | 8.2.1 | Rate limiting middleware |
| nodemailer | 8.0.1 | Email sending |
| cookie-parser | 1.4.7 | Parse cookie headers |
| morgan | 1.10.1 | HTTP request logger |
| dotenv | 17.3.1 | Environment variables |
| moment | 2.30.1 | Date/time manipulation |
| Package | Version | Purpose |
|---|---|---|
| typescript | 5.9.3 | TypeScript compiler |
| tsx | 4.21.0 | TypeScript execution & watch |
| @types/* | Latest | TypeScript type definitions |
Ensure you have the following installed:
Node.js >= 18.x
npm >= 9.x
MongoDB (local or Atlas)- Clone the repository
git clone https://github.com/JomsCode21/Bare-Minimum-Planner-Back-End.git
cd Bare-Minimum-Planner-Back-End- Install dependencies
npm install- Configure environment variables
Create a .env file in the root directory:
# Server Configuration
PORT=5000
NODE_ENV=development
# Database
MONGODB_URI=mongodb://localhost:27017/bare-minimum-planner
# OR for MongoDB Atlas:
# MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/bare-minimum-planner
# JWT Configuration
JWT_SECRET=your_super_secret_jwt_key_here_minimum_32_characters
JWT_EXPIRES_IN=7d
# Email Configuration (Gmail example)
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_SECURE=false
EMAIL_USER=your-email@gmail.com
EMAIL_PASSWORD=your-app-specific-password
EMAIL_FROM=Bare Minimum Planner <noreply@bareminimumplanner.com>
# Frontend URL (for CORS)
FRONTEND_URL=http://localhost:5173
# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100- Start the development server
npm run devThe server will start on http://localhost:5000 π
backend/
βββ src/
β βββ config/ # Configuration files
β β βββ mail.config.ts # Email configuration
β β
β βββ controllers/ # Route controllers (business logic)
β β βββ task.controller.ts # Task CRUD operations
β β βββ user.controller.ts # User authentication & management
β β
β βββ db/ # Database connection
β β βββ index.ts # MongoDB connection setup
β β
β βββ middlewares/ # Custom middleware functions
β β βββ global-error-handler.middleware.ts
β β βββ limiter.middleware.ts # Rate limiting
β β βββ verify-token.middleware.ts # JWT authentication
β β
β βββ models/ # Mongoose models (schemas)
β β βββ task.models.ts # Task schema & model
β β βββ user.model.ts # User schema & model
β β
β βββ routes/ # API route definitions
β β βββ taskRoutes.ts # Task endpoints
β β βββ userRoutes.ts # User & auth endpoints
β β
β βββ utils/ # Utility functions
β β βββ mail.ts # Email sending utilities
β β βββ ForgotPassword.ts # Password reset logic
β β βββ error/
β β βββ app-error.util.ts # Custom error handler
β β
β βββ index.ts # Application entry point
β
βββ .env # Environment variables (not in git)
βββ .env.example # Environment template
βββ .gitignore # Git ignore rules
βββ package.json # Dependencies & scripts
βββ tsconfig.json # TypeScript configuration
βββ README.md # This file
http://localhost:5000/api
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/users/register |
Register a new user account | β No |
POST |
/users/login |
Login with email and password | β No |
POST |
/users/logout |
Logout current user | β Yes |
GET |
/users/check-auth |
Verify authentication status | β Yes |
POST |
/users/check-email |
Check if email exists | β No |
POST |
/users/forgotpassword |
Request password reset email | β No |
PUT |
/users/:id |
Update user information | β Yes |
GET |
/users/ |
Get all users (admin) | β No |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET |
/tasks |
Get all tasks for authenticated user | β Yes |
POST |
/tasks |
Create a new task | β Yes |
PUT |
/tasks/:id |
Update a specific task | β Yes |
DELETE |
/tasks/:id |
Delete a specific task | β Yes |
Request:
POST /api/users/register
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com",
"password": "SecurePassword123!"
}Response (201 Created):
{
"success": true,
"message": "User registered successfully",
"user": {
"id": "507f1f77bcf86cd799439011",
"name": "John Doe",
"email": "john@example.com"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Request:
POST /api/users/login
Content-Type: application/json
{
"email": "john@example.com",
"password": "SecurePassword123!"
}Response (200 OK):
{
"success": true,
"message": "Login successful",
"user": {
"id": "507f1f77bcf86cd799439011",
"name": "John Doe",
"email": "john@example.com"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Request:
POST /api/tasks
Content-Type: application/json
Authorization: Bearer <jwt_token>
{
"title": "Complete project documentation",
"description": "Write comprehensive README files",
"isCompleted": false
}Response (201 Created):
{
"success": true,
"message": "Task created successfully",
"task": {
"id": "507f191e810c19729de860ea",
"title": "Complete project documentation",
"description": "Write comprehensive README files",
"isCompleted": false,
"userId": "507f1f77bcf86cd799439011",
"createdAt": "2026-02-19T10:30:00.000Z",
"updatedAt": "2026-02-19T10:30:00.000Z"
}
}Request:
GET /api/tasks
Authorization: Bearer <jwt_token>Response (200 OK):
{
"success": true,
"count": 3,
"tasks": [
{
"id": "507f191e810c19729de860ea",
"title": "Complete project documentation",
"description": "Write comprehensive README files",
"isCompleted": false,
"createdAt": "2026-02-19T10:30:00.000Z"
}
// ... more tasks
]
}sequenceDiagram
participant Client
participant API
participant Database
participant JWT
Client->>API: POST /users/register
API->>Database: Create User
Database-->>API: User Created
API->>JWT: Generate Token
JWT-->>API: JWT Token
API-->>Client: User Data + Token (Cookie)
Client->>API: POST /users/login
API->>Database: Verify Credentials
Database-->>API: User Found
API->>JWT: Generate Token
JWT-->>API: JWT Token
API-->>Client: User Data + Token (Cookie)
Client->>API: GET /tasks (with token)
API->>JWT: Verify Token
JWT-->>API: Token Valid
API->>Database: Fetch Tasks
Database-->>API: Tasks Data
API-->>Client: Tasks Response
// Passwords are hashed using bcrypt with salt rounds
const saltRounds = 10;
const hashedPassword = await bcrypt.hash(password, saltRounds);// JWT tokens are signed and verified with a secret key
const token = jwt.sign({ userId: user._id }, JWT_SECRET, {
expiresIn: "7d",
});// Prevents brute force attacks
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // Limit each IP to 100 requests per windowMs
message: "Too many requests from this IP",
});- Content Security Policy
- X-Frame-Options
- X-Content-Type-Options
- Strict-Transport-Security
- X-Download-Options
- X-DNS-Prefetch-Control
| Command | Description |
|---|---|
npm run dev |
π₯ Start development server with hot reload and auto-restart |
npm run typecheck |
π Run TypeScript type checking without emitting files |
# Start development server
npm run dev
# The server will:
# β
Watch for file changes
# β
Auto-reload on changes
# β
Load environment variables from .env
# β
Show detailed error messages
# β
Log all HTTP requests (morgan){
name: String (required),
email: String (required, unique),
password: String (required, hashed),
createdAt: Date,
updatedAt: Date
}{
title: String (required),
description: String,
isCompleted: Boolean (default: false),
userId: ObjectId (ref: 'User', required),
createdAt: Date,
updatedAt: Date
}The application automatically connects to MongoDB on startup:
// Local MongoDB
mongodb://localhost:27017/bare-minimum-planner
// MongoDB Atlas
mongodb+srv://<username>:<password>@cluster.mongodb.net/bare-minimum-plannercors({
origin: "http://localhost:5173", // Frontend URL
credentials: true, // Allow cookies
});| Variable | Required | Default | Description |
|---|---|---|---|
PORT |
No | 5000 | Server port |
MONGODB_URI |
Yes | - | MongoDB connection string |
JWT_SECRET |
Yes | - | Secret key for JWT signing |
JWT_EXPIRES_IN |
No | 7d | JWT expiration time |
EMAIL_HOST |
Yes | - | SMTP host |
EMAIL_PORT |
Yes | - | SMTP port |
EMAIL_USER |
Yes | - | Email account |
EMAIL_PASSWORD |
Yes | - | Email password/app password |
FRONTEND_URL |
Yes | - | Frontend application URL |
The API uses a global error handler that returns consistent error responses:
{
"success": false,
"error": {
"message": "Error description",
"statusCode": 400,
"stack": "Error stack trace (development only)"
}
}| Code | Meaning |
|---|---|
| 200 | Success |
| 201 | Created |
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
| 409 | Conflict (e.g., email already exists) |
| 429 | Too Many Requests (rate limit) |
| 500 | Internal Server Error |
You can test the API using tools like:
# Register a new user
curl -X POST http://localhost:5000/api/users/register \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com",
"password": "SecurePassword123!"
}'
# Login
curl -X POST http://localhost:5000/api/users/login \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "SecurePassword123!"
}'
# Create a task (with auth token)
curl -X POST http://localhost:5000/api/tasks \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"title": "Test Task",
"description": "Task description"
}'- Node.js hosting (Heroku, Railway, Render, DigitalOcean, AWS, etc.)
- MongoDB Atlas (cloud database)
- Environment variables configured on hosting platform
-
Set up MongoDB Atlas
- Create a free cluster at MongoDB Atlas
- Get your connection string
- Whitelist your application's IP
-
Configure Environment Variables
- Set all required
.envvariables on your hosting platform - Use production-grade secrets for
JWT_SECRET - Update
FRONTEND_URLto your production domain
- Set all required
-
Deploy
# Build TypeScript (if needed)
npm run build
# Start production server
npm start|
Fast, easy deployment with built-in PostgreSQL/MongoDB support |
Free tier available with automatic HTTPS |
Classic PaaS with extensive add-ons |
Server won't start
# Check if port is already in use
netstat -ano | findstr :5000 # Windows
lsof -i :5000 # macOS/Linux
# Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm installDatabase connection failed
- Verify MongoDB is running (local):
# Windows
net start MongoDB
# macOS/Linux
sudo systemctl start mongod- Check connection string format
- Verify network access (MongoDB Atlas)
- Check firewall settings
JWT authentication errors
- Ensure
JWT_SECRETis set in.env - Check token expiration time
- Verify Authorization header format:
Bearer <token> - Clear cookies and login again
Email not sending
- Verify SMTP credentials
- For Gmail: Enable "Less secure app access" or use App Password
- Check email service provider's sending limits
- Verify network connectivity
CORS errors
- Verify
FRONTEND_URLmatches exactly - Include trailing slash if necessary
- Check credentials configuration
- Ensure frontend sends credentials
- π Express.js Documentation
- π Mongoose Documentation
- π JWT.io
- π§ Nodemailer Documentation
- π‘οΈ Helmet.js
We welcome contributions! Here's how you can help:
- π΄ Fork the repository
- πΏ Create a feature branch
git checkout -b feature/amazing-feature
- βοΈ Commit your changes
git commit -m 'Add some amazing feature' - π€ Push to the branch
git push origin feature/amazing-feature
- π Open a Pull Request
- Write clear, descriptive commit messages
- Follow existing code style and patterns
- Add comments for complex logic
- Test your changes thoroughly
- Update documentation as needed
This project is licensed under the ISC License.
JomsCode21 π§ π» π |
- π Express.js Team - For the robust web framework
- π MongoDB Team - For the flexible NoSQL database
- π Node.js Security Community - For security best practices
- π§ Nodemailer Team - For email functionality
- π Open Source Community - For amazing packages and support
- π¨ Frontend Repository
- π API Documentation
- π Report Issues
- π¬ Discussions
Built with π and β by the Bare Minimum Planner Team