Namskaram! 🙏 Welcome to the Express.js TypeScript Starter. This project provides a solid foundation for building RESTful APIs and web applications with Express.js, leveraging the power of TypeScript for type safety and improved developer experience.
- TypeScript: Enhanced code quality, maintainability, and tooling with static typing.
- Express.js: Minimalist and flexible web application framework for Node.js.
- Authentication: Secure user authentication with JSON Web Tokens (JWT).
- MongoDB Integration: Database integration using Mongoose for seamless data modeling and interaction.
- Redis Caching: Optional integration with Redis for improved performance through data caching.
- Morgan Logging: Configurable request logging with Morgan.
- Helmet Security: Essential security middleware to protect against common vulnerabilities.
- CORS Support: Easily manage Cross-Origin Resource Sharing (CORS) for your API.
- Input Validation: Use Express Validator for robust validation of incoming request data.
- Rate Limiting: Prevent abuse with Express Rate Limit.
- Testing: Jest testing framework for writing unit and integration tests.
- Node.js: Make sure you have Node.js and NPM (Node Package Manager) installed. You can download them from the official website: https://nodejs.org/
- MongoDB: Install and run a MongoDB instance. Refer to the MongoDB documentation for installation instructions: https://docs.mongodb.com/manual/installation/
- Redis (Optional): If you want to use Redis for caching, install it. See the Redis installation guide: https://redis.io/docs/getting-started/
-
Clone the Repository:
git clone https://github.com/theakashshukla/express-ts-starter.git cd express-ts-starter
-
Install Dependencies:
npm install
-
Setup Environment Variables:
Create a .env file in the root of your project and add your environment variables. You can start by copying the example file:
cp .env.example .env
-
Install TypeScript (if not already installed:
npm install -g typescript
-
Start the Development Server:
npm run dev
-
Production Build:
npm run build
-
Run Prodcution Server
npm run start
-
Run Tests:
npm run test
-
Prettier:
npm run format
The project structure is designed to provide a clear and organized way to build your application. Here's an overview of the structure:
express-ts-starter/
├── src
│ ├── config
│ │ ├── dbConfig.ts
│ │ ├── index.ts
│ │ ├── redisConfig.ts
│ ├── controllers
│ │ └── userController.ts
│ ├── middlewares
│ │ ├── authMiddleware.ts
│ │ ├── authorizationMiddleware.ts
│ │ ├── rateLimit.ts
│ │ ├── validationMiddleware.ts
│ │ └── errorHandler.ts
│ ├── models
│ │ └── userModel.ts
│ ├── routes
│ │ ├── index.ts
│ │ ├── health.ts
│ │ └── userRoutes.ts
│ ├── services
│ │ ├── userService.ts
│ ├── utils
│ │ ├── authUtils.ts
│ │ ├── bcryptUtils.ts
│ │ ├── logger.ts
│ │ └── token.ts
│ |── validators
│ │ ├── userValidator.ts
│ | └── serviceValidator.ts
│ └── app.ts
├── tests
├── .env
├── .env.example
├── .gitignore
├── jest.config.js
├── package.json
├── tsconfig.json
└── README.md
-
npm run dev
: Start the development server with Nodemon. -
npm run build
: Compile TypeScript to JavaScript. -
npm run start
: Start the production server. -
npm run test
: Run tests using Jest. -
npm run format
: Format code using Prettier.
This project uses the Jest testing framework for writing unit and integration tests. You can find the test files in the tests
directory. To run the tests, use the following command:
npm run test
Contributions are welcome! Feel free to open an issue or submit a pull request if you find a bug or want to add a new feature.
This project is open-source and available under the ISC License.