This is my express starter for building rest api with typescript , JWT , mongodb
The project follows a modular architecture, with components organized into the following directories inside the src
folder:
- config: Contains configuration files for the application, such as environment variables and database configurations.
- controller: Handles incoming requests, processes them, and returns appropriate responses.
- db: Manages database interactions, including connecting to the database, defining models, and executing queries.
- middleware: Contains middleware functions that intercept requests before they reach the route handlers, used for authentication, error handling, etc.
- routes: Defines the routes for different API endpoints, mapping them to corresponding controller functions.
- services: Contains business logic for various functionalities of the application, separating it from the controller layer.
- test: Houses test files for unit and integration testing, ensuring the reliability and correctness of the code.
- types: Contains TypeScript type definitions for better code readability and maintainability.
- utils: Holds utility functions used across different parts of the application, promoting code reusability.
- Express (4.18.2): Web framework for Node.js, used for building the backend server.
- Mongoose (7.4.0): MongoDB object modeling tool designed to work in an asynchronous environment.
- Jest (29.7.0): JavaScript testing framework used for writing and running tests.
- Supertest (6.3.3): HTTP assertion library, used with Jest for testing HTTP endpoints.
- JWT (9.0.1): JSON Web Token implementation for user authentication.
- Nodemailer (6.9.4): Module for sending emails, used for notification purposes.
- Winston (3.11.0): Logging library for Node.js, used for logging application events and errors.
- Cors (2.8.5): Middleware for enabling Cross-Origin Resource Sharing (CORS) in Express.js.
- Express Validator (7.0.1): Middleware for validating request data in Express.js applications.
- Cloudinary (2.0.1): Media management solution for handling image and video uploads.
npm run build
: "Transpile TypeScript files into JavaScript using TypeScript compiler.",npm run dev
: "Start development server with live reloading for TypeScript files.",npm run doc
: "Generate documentation using TypeDoc.",npm run seed
: Seed the database with initial data after transpiling TypeScript files.",npm run start
: "Start the production server.",npm run test
: "Run tests using Jest with environment setup and cache disabled.",npm run lint
: "Lint TypeScript files for code quality issues.",npm run lint:fix
: "Automatically fix linting errors in TypeScript files."
Follow these steps to set up and run the project locally:
- Clone the repository:
git clone https://github.com/MicroClub-USTHB/challenges-platform-rest-api
- Navigate to the project directory:
cd express-starter
- Install dependencies:
npm install
oryarn install
- Set up environment variables ( database connection string, JWT secret) you can find it in .env.example
- Start the backend server:
npm start
oryarn start