A secure backend API for managing todos with user authentication, built with Express.js and MongoDB.
Topics: todo
backend
mongodb
express
jwt
nodejs
rest-api
- User signup and signin with email validation
- JWT Authentication with 30-day expiration
- Password hashing with bcrypt
- CRUD operations for todos
- Input validation with Zod
- MongoDB database integration
- Express.js - Backend server
- MongoDB - Database
- Mongoose - MongoDB ODM
- JWT - Authentication
- Bcrypt - Password hashing
- Zod - Input validation
Mongo_class/
├── index.js # Main server & API routes
├── db.js # Database models
├── package.json # Dependencies & scripts
├── .env # Environment variables
└── .gitignore # Git ignore rules
-
Clone the repository
git clone <repository-url> cd Mongo_class
-
Install dependencies
npm install
-
Set up environment variables
echo "JWT_SECRET=your-secret-key" > .env echo "DB_URL=your-mongodb-connection-string" >> .env
-
Start the server
node index.js
-
Server runs on -
http://localhost:3000
Method | Endpoint | Description |
---|---|---|
POST |
/signup |
Create account |
POST |
/signin |
User login |
Method | Endpoint | Description |
---|---|---|
POST |
/todo |
Create new todo |
GET |
/todos |
Get user's todos |
- User creates account with email validation
- Password gets hashed and stored securely
- JWT token generated on successful signin
- Token required for all todo operations
- Users can create and view their todos
Frontend will be built with React (coming soon!)
Built with ❤️ by Sahil Singh