https://github.com/exposedcat/express-mongodb-template
Express.JS + MongoDB API template
https://github.com/exposedcat/express-mongodb-template
Last synced: 10 months ago
JSON representation
Express.JS + MongoDB API template
- Host: GitHub
- URL: https://github.com/exposedcat/express-mongodb-template
- Owner: ExposedCat
- Created: 2022-06-06T21:18:30.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-25T11:21:20.000Z (over 3 years ago)
- Last Synced: 2025-01-18T14:34:17.627Z (12 months ago)
- Language: TypeScript
- Size: 196 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
HTTP API template on Express + MongoDB
[](https://github.com/ExposedCat/express-mongodb-template#via-heroku)
[](https://github.com/ExposedCat/express-mongodb-template#-running)
[](https://app.swaggerhub.com/apis-docs/artem-prokop/express-mongodb-template/1.0.0)

⭐️ Features
- Convenient for frontend usage
- Strict code formatting rules
- Scalable file architecture
- 100% of API documented
-
Docker support -
Heroku support - Automatic tests
- Well-readable git repository with beautiful README
⚙️ Stack
- Programming language: Node.JS
- API: Express.JS
- Users storage: Mongodb, Mongoose.JS
- Testing tools: Mocha, Chai
- Running tools: Nodemon, Docker, Heroku
🔌 Running
via Docker
0. Install [Docker](https://docs.docker.com/get-docker/)
1. Clone this repo:
```bash
git clone https://github.com/ExposedCat/express-mongodb-template.git
```
2. Go to project root:
```bash
cd express-mongodb-template
```
3. Create copy of `.env-example` called `.env` and replace example data with yours
4. Build app image:
```bash
docker build -t express-mongodb-api .
```
5.
- Start app (map local port 3000 to the same in container):
```bash
docker run -dp 3000:3000 express-mongodb-api
```
- Start app with local DB image:
1. Add `DB_NAME` in `.env` file and put local db name there, for instance `express-mongodb-users`
2. Use `express-mongodb-db:27017` as database URI in `DB_CONNECTION_STRING`
3. Build and run app and local DB:
```bash
docker-compose up -d --build
```
**Done**.
via Nodemon
for development
0. Install and run MongoDB server
1. Clone this repo:
```bash
git clone https://github.com/ExposedCat/express-mongodb-template.git
```
2. Go to project root:
```bash
cd express-mongodb-template
```
3. Create copy of `.env-example` called `.env` and replace example data with yours
4. Install dependencies:
```bash
npm install
```
5. Start app:
```bash
npm run dev
```
**Done**.
via Heroku
0. Get any cloud database, for ex. MongoDB Atlas
1. Clone this repo:
```bash
git clone https://github.com/ExposedCat/express-mongodb-template.git
```
2. Go to project root:
```bash
cd express-mongodb-template
```
3. At Heroku → `App` → `Settings` → `Config vars`
Set environment variables:
Connection string of MongoDB database
```bash
DB_CONNECTION_STRING
```
Secret for generating JWT
```bash
JWT_SECRET
```
Port for API to run on
```bash
PORT
```
Secret for Express.JS session
```bash
SESSION_SECRET
```
4. Follow instructions at Heroku → `App` → `Deploy`
**Done**.
🐛 Testing
1. Create copy of `.env-example` called `.env-test` and replace example data with your test data
2. Run tests:
```bash
npm run test
```
🔩 Dependencies
Production
- Express.JS, Express-Session
- Async Json-Web-Token
- Mongoose.JS
- DotEnv
- Helmet
- Bcrypt
Development
- Nodemon
- Prettier