An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          


HTTP API template on Express + MongoDB

[![Developer](https://img.shields.io/badge/Heroku-Compatible-gray?style=for-the-badge&logo=heroku&labelColor=purple)](https://github.com/ExposedCat/express-mongodb-template#via-heroku)
[![Developer](https://img.shields.io/badge/Docker-Support-gray?style=for-the-badge&logo=docker&labelColor=blue&logoColor=white)](https://github.com/ExposedCat/express-mongodb-template#-running)
[![Developer](https://img.shields.io/badge/Swagger-Docs-green?style=for-the-badge&logo=swagger)](https://app.swaggerhub.com/apis-docs/artem-prokop/express-mongodb-template/1.0.0)

App preview


⭐️ 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