This repository provides a production-grade backend template for Node.js applications using Express.js and TypeScript, with Mongoose for MongoDB integration. It includes a foundational structure, environment configuration, and a basic User model to jump start your backend development.
.env
file for secure storage of sensitive data (e.g., database credentials, API keys)..gitignore
for keeping sensitive files out of version control..prettierrc
for consistent code style.Backend Template TypeScript/
├── node_modules/ # Dependencies
├── public/ # Static assets
├── src/ # Main source code
│ ├── index.ts # Entry point
│ ├── app.ts # Express app setup
│ ├── constant.ts # Constants file
│ ├── controllers/ # Controller files
│ │ └── user.controller.ts
│ ├── db/ # Database connection setup
│ │ └── database.ts
│ ├── middlewares/ # Middleware functions
│ │ ├── auth.middleware.ts
│ │ └── multer.middleware.ts
│ ├── models/ # Data models
│ │ └── user.model.ts
│ ├── routes/ # Route handlers
│ │ └── user.routes.ts
│ └── utils/ # Utility functions
│ ├── ApiError.ts
│ ├── ApiResponse.ts
│ ├── asyncHandler.ts
│ └── cloudinary.ts
├── .env # Environment variables
├── .env.example # Example .env file
├── .eslintrc.json # ESLint configuration
├── .gitignore # Git ignore file
├── package-lock.json # Locked dependencies
├── package.json # Project dependencies and scripts
├── Readme.md # Project documentation
└── tsconfig.json # TypeScript configuration
Create a .env
file in the root directory and add the following:
# Example .env file
PORT=4000
MONGODB_URL=YourMongoDBURL
CORS_ORIGIN=*
ACCESS_TOKEN_SECRET=Darshan
ACCESS_TOKEN_EXPIRY=1d
REFRESH_TOKEN_SECRET=Dpvasani
REFRESH_TOKEN_EXPIRY=10d
CLOUDINARY_CLOUD_NAME=YourCloudName
CLOUDINARY_API_KEY=YourApiKey
CLOUDINARY_API_SECRET=YourApiSecret
git clone https://github.com/dpvasani/Backend-Template-TypeScript
cd Backend-Template-TypeScript
npm install
.env
file.To run the development server:
npm run dev
This will start the development server.
Feel free to open issues or create pull requests if you have suggestions for improvements!
This project is licensed under the MIT License.