Skip to content

seniorpe/nodejs-express-mongodb-jwt

Repository files navigation

Node.js, Express Framework, MongoDB and JWT

Development

We use node version 14.9.0

nvm install 14.9.0
nvm use 14.9.0

The first time, you will need to run

npm install

Then just start the server with

npm run start

It uses nodemon for livereloading :peace-fingers:

Online one-click setup

You can use Gitpod for the one click online setup. With a single click it will launch a workspace and automatically:

  • clone the nodejs-express-mongodb-jwt repo.
  • install the dependencies.
  • run cp .env.example .env.
  • run npm run start.

Open in Gitpod

API Validation

By using celebrate, the req.body schema becomes cleary defined at route level, so even frontend devs can read what an API endpoint expects without needing to write documentation that can get outdated quickly.

route.post('/signup',
 celebrate({
   body: Joi.object({
     name: Joi.string().required(),
     email: Joi.string().required(),
     password: Joi.string().required(),
   }),
 }),
 controller.signup)

Example error

{
 "errors": {
   "message": "child \"email\" fails because [\"email\" is required]"
 }
}

Read more about celebrate here and the Joi validation API

Roadmap

  • API Validation layer (Celebrate+Joi)
  • The logging 'layer'
  • Continuous integration with CircleCI 😍

Reference

This is the example repository from the blog post 'Bulletproof node.js project architecture'