Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dpvasani/backend-template
This repository provides a production-grade backend template for Node.js applications using Express.js and MongoDB. It includes a foundational structure, environment configuration, and a basic User model to help jump start backend development.
https://github.com/dpvasani/backend-template
backend backend-api expressjs mern-stack mongodb mongoose mvc-architecture nodejs rest-api
Last synced: 21 days ago
JSON representation
This repository provides a production-grade backend template for Node.js applications using Express.js and MongoDB. It includes a foundational structure, environment configuration, and a basic User model to help jump start backend development.
- Host: GitHub
- URL: https://github.com/dpvasani/backend-template
- Owner: dpvasani
- Created: 2024-10-10T15:00:54.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-10-22T03:10:20.000Z (3 months ago)
- Last Synced: 2024-11-10T13:41:22.523Z (2 months ago)
- Topics: backend, backend-api, expressjs, mern-stack, mongodb, mongoose, mvc-architecture, nodejs, rest-api
- Language: JavaScript
- Homepage:
- Size: 43 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Backend-Template
This repository provides a production-grade backend template for Node.js applications using Express.js and MongoDB. It includes a foundational structure, environment configuration, and a basic User model to help jump start backend development.
## Features
- **Production-Grade Setup**: Configured for scalability, security, and performance.
- **Express.js**: Minimalist web framework for routing and middleware.
- **MongoDB**: Integrated with Mongoose ORM for schema management and database operations.
- **User Model**: Pre-configured with basic fields like `name`, `email`, and `password`.
- **Prettier**: Code formatting with custom rules for maintaining code consistency.
- **Environment Configuration**: `.env` file for secure storage of sensitive data (e.g., database credentials, API keys).
- **Git Best Practices**: `.gitignore` for keeping sensitive files out of version control.## Folder Structure
```bash
Backend-Template/
├── public/ # Public assets (if any)
│ └── temp/ # Temporary files or uploads
├── src/ # Main application code
│ ├── controllers/ # Route controllers (business logic)
│ ├── models/ # Mongoose models (database schema)
│ ├── routes/ # Route definitions (API endpoints)
│ ├── middlewares/ # Custom middleware (e.g., authentication)
│ ├── config/ # Configuration files (e.g., database setup)
│ ├── services/ # Service logic (e.g., external API calls, utilities)
│ └── app.js # Main application file
├── .env # Environment variables
├── .gitignore # Ignored files for version control
├── .prettierignore # Files ignored by Prettier
├── .prettierrc # Prettier configuration
├── package.json # Project dependencies and scripts
├── package-lock.json # Lockfile for consistent dependency versions
└── README.md # Project documentation
```## Getting Started
### Prerequisites
- Node.js (v14 or later)
- MongoDB (local or cloud instance)
- Environment variables configured in a `.env` file### Environment Variables
Create a `.env` file in the root directory and add the following:
```bash
# Example .env filePORT=Your Port
MONGODB_URL=MongoDB URL
CORS_ORIGIN=*
ACCESS_TOKEN_SECRET=Darshan Vasani
ACCESS_TOKEN_EXPIRY=1d
REFRESH_TOKEN_SECRET=Backend
REFRESH_TOKEN_EXPIRY=10d
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=
```### Installation
1. Clone the repository:
```bash
git clone https://github.com/dpvasani/Backend-Template.git
cd Backend-Template
```2. Install dependencies:
```bash
npm install
```3. Set up your MongoDB connection in the `.env` file.
4. Start the server:
```bash
npm run dev
```## Contributing
Feel free to open issues or create pull requests if you have suggestions for improvements!
## License
This project is licensed under the MIT License.