A simple API boilerplate build with express+mongoDB+JWT written in ES6.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Expressful Pot

Build Status codecov

A simple API boilerplate build with express+mongoDB+JWT written in ES6.

Content Development

├── .babelrc
├── package.json
└── src
    ├── app
    │   ├── http
    │   │   ├── controllers
    │   │   │   ├── authController.js
    │   │   │   └── userController.js
    │   │   ├── middlewares
    │   │   │   └── auth.js
    │   │   ├── apiRoutes.js
    │   │   ├── authRoutes.js
    │   │   └── routes.js
    │   ├── models
    │   │   └── user.js        
    │   └── utils
    │       ├── HttpError.js
    │       ├── jwt.js
    │       └── logger.js    
    ├── bootstrap
    │   ├── app.js
    │   ├── express.js
    │   ├── mongoose.js
    │   └── server.js
    ├── config
    │   └── index.js
    ├── seeds
    │   └── users.js
    └── storage
        └── logs

This folder contains controllers, middlewares, and routes. Almost all of the logic to handle requests will be placed in this directory. The boilerplate includes:

  • /controllers
    • authController.js basic controller for auth routes.
    • userController.js basic controller for user routes.
  • /middlewares
    • auth.js middleware for JWT token verification. token, user id , and user role are saved in Express response.locals if auth is ok. Every request that involves this middleware will verify the JWT, if the token is still valid and its expiration time is below 6 hours (default configuration), then it will send a fresh valid token with expiration date to 24 hours (default configuration). This new token will be appended in the request.
  • /apiRoutes.js contains all the API routes.
  • /authRoutes.js contains all the authorization routes.
  • /routes.js contains all the Application routes.

This folder contains all the models of the application. The boilerplate includes the user.js model with basic fields for authentification and password reset :

  • email
  • role - [user | admin]
  • password
  • passwordResetToken
  • passwordResetExpires

This folder contains all the utils for the application. The boilerplate includes:

  • HttpError.js is used to raise errors along with Express next() method, e.g. return next(new HttpError()).
  • jwt.js is the responsable for JWT signature and verification.
  • logger.js is the responsable for the logger object

This folder contains files that bootstrap expressful pot. The boilerplate includes:

  • app.js is our application bootstrap. Connects mongodb and start listening express.
  • express.js is where general express configuration resides. e.g. Application-level middleware like body-parser or morgan.
  • mongoose.js is the responsable for connecting/closing with MongoDB.
  • server.js is the responsable for creating the HTTP Server and listen on provided port.

This folder contains all the configuration of the application. The boilerplate includes:

  • index.js is where development and production configurations resides, e.g. jwt.secret or app.host.

This folder contains all the seeds for development. The boilerplate includes users.js, please consider that every user needs to hash his password, using the users.js approach is not optimal for a huge seed, please consider insertMany or collection.insert, but be aware that none of them trigger middlewares.

Use this folder for anything that needs to be stored. This Boilerplate includes:

  • logs where all the logs are saved

API Documentation

For detailed information head over to the full documentation hosted by apiary.

Getting Started

Clone the repo:

git clone https://github.com/AlgusDark/expressful-pot
cd expressful-pot

Install dependencies:

npm install

Run the server in development environment:

npm run serve

Seed mongodb with some users. This will seed users with password as 'password'.

npm run seed:users

Run tests:

# Run unit & integration tests
npm test 

# Run unit tests
npm test:unit
# Run unit tests with code coverage
npm test:unit-cover

# Run integration tests
npm test:integration
# Run integration tests with code coverage
npm test:integration-cover

Build the app and start the server in production environment:

npm run build
npm run start


You can view the issue list and do a Pull Request.

Author & License

Created by Carlos Pérez Gutiérrez under the MIT license.