Caffeine is a platform designed for programmers and tech enthusiasts. The app provides a space to share posts, follow users, interact with content, and manage coding-related resources.
This repository contains the Node.js-based backend API.
- Node.js: JavaScript runtime for building scalable server-side applications.
- Express.js: Web framework for creating RESTful APIs.
- MongoDB (Atlas): NoSQL database for data storage.
- Mongoose: MongoDB object modeling for Node.js.
- Migration-Mongo: For database schema and data migrations.
- Jest: Testing framework for unit and integration tests.
- Nodemailer: For handling email communication (password recovery, notifications, etc.).
- RESTful API: Handles user authentication, post interactions, and data operations.
- Authentication: Secure JWT-based user authentication.
- Validation: Ensures data integrity using Mongoose schemas.
- Email Integration: Send emails for password recovery and notifications using Nodemailer.
- API Documentation: Fully documented API endpoints in Postman (see below).
- Database Migrations: Manage incremental changes with Migration-Mongo.
Explore the API endpoints with the provided Postman collection: Postman Collection
POST /api/v1/auth/register: Register a new user.POST /api/v1/auth/login: User login.POST /api/v1/auth/forgot-password: Request password reset email.POST /api/v1/auth/reset-password: Reset user password.
GET /api/v1/posts: Get all posts with pagination.POST /api/v1/post: Create a new post.PUT /api/v1/post/:id: Update a specific post.DELETE /api/v1/post/:id: Delete a specific post.
GET /api/v1/users/:id: Fetch user details.PUT /api/v1/users/update/:id: Update user details.POST /api/v1/users/follow/:id: Follow another user.POST /api/v1/users/unfollow/:id: Unfollow another user.
- Node.js (v16+)
- MongoDB (Atlas or Local Instance)
- Expo CLI
- Postman (optional, for testing API endpoints)
Create a .env file in the root directory and populate it with the following variables:
MONGODB_URI=
DATABASE_NAME=Test1
SECRET_KEY=your_secret_key
CLOUDINARY_NAME=your_cloudinary_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_secret
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your_email@example.com
EMAIL_PASS=your_email_password
RESET_TOKEN_SECRET=reset_token_secret
RESET_TOKEN_EXPIRATION=3600
FRONTEND_URL=http://localhost:8081-
Install dependencies:
npm install
-
Run database migrations:
npx migrate-mongo up
-
Start the backend server:
npm start
-
Run tests:
npm test
Use Postman to test the API or integrate the endpoints directly into your mobile app. See the Postman Collection for examples.
To create a new migration:
-
Generate a new migration file:
npx migrate-mongo create migration_name
-
Implement the
upanddownfunctions in the generated file.
- Apply migrations:
npx migrate-mongo up
- Rollback the last migration:
npx migrate-mongo down
The project uses Jest for testing. Run tests using:
npm test- Fork the repository and create a new branch.
- Make your changes and test thoroughly.
- Submit a pull request with a detailed description of the changes.
This project is licensed under the MIT License. See the LICENSE file for details.
Enjoy building and contributing to Caffeine! ☕