A comprehensive backend application with various features including user management, product management, order processing, notifications, and more.
- Features
- Prerequisites
- Installation
- Usage
- API Endpoints
- Scheduled Jobs
- Utilities
- Contributing
- License
- User Management: Register, login, and manage user profiles.
- Product Management: Add, update, delete, and list products.
- Order Processing: Place and manage orders.
- Notifications: Send and manage notifications.
- Search: Elasticsearch integration for product search.
- Database: MongoDB integration for data persistence.
- Caching: Redis integration for caching.
- Email: Nodemailer integration for sending emails.
- Logging: Comprehensive logging using Winston.
- Error Handling: Global error handler for handling exceptions.
- Validation: Input validation using express-validator.
- Rate Limiting: API rate limiting to prevent abuse.
- Authentication & Authorization: JWT-based authentication and role-based authorization.
- Scheduled Jobs: Cron jobs for tasks like sending weekly newsletters, database backups, and more.
- Node.js
- MongoDB
- Redis
- Elasticsearch
- Clone the repository:
git clone https://github.com/asterginete/api-expressjs-typescript.git
cd api-expressjs-typescript
- Install dependencies:
npm install
- Create a
.env
file in the root directory and set up your environment variables:
MONGODB_URI=mongodb://localhost:27017/myapp
REDIS_URL=redis://localhost:6379
ELASTICSEARCH_URI=http://localhost:9200
JWT_SECRET=jwt_secret
EMAIL_FROM=[email protected]
-
Start the services (MongoDB, Redis, Elasticsearch).
-
Run the application:
npm start
Once the server is running, you can access the API at http://localhost:3000/api
.
-
Users:
- POST
/api/users/register
: Register a new user. - POST
/api/users/login
: Login a user. - GET
/api/users/profile
: Fetch user profile. - PUT
/api/users/profile
: Update user profile. - DELETE
/api/users/:userId
: Delete a user.
- POST
-
Products:
- POST
/api/products
: Add a new product. - GET
/api/products
: List all products. - GET
/api/products/:productId
: Fetch a specific product. - PUT
/api/products/:productId
: Update a product. - DELETE
/api/products/:productId
: Delete a product.
- POST
... (similarly for orders and notifications)
- Weekly Newsletter: Sends a newsletter every Sunday at 9 AM.
- Database Backup: Backs up the database every day at 2 AM.
- Clean Up Logs: Cleans up log files every month on the 1st at 3 AM.
- Update Search Index: Updates the Elasticsearch index every day at 4 AM.
- Logger: Provides comprehensive logging for the application.
- Error Handler: Handles exceptions and sends appropriate responses.
- Validator: Validates input data for API requests.
- Paginator: Provides pagination utilities for listing endpoints.
- Fork the repository.
- Create a new branch.
- Make your changes.
- Submit a pull request.
This project is licensed under the ISC License.