This is a minimalist express boilerplate with the following features:
ECMA Script 2020or ES2020 features enabled
Babelto transpile the js code
DotenvLoad environment variables from .env file
EslintCode quality tool
Prettierto prettify the code
MongoDBready to go configuration with mongoose
CORSfeature enabled
Passportauthentication strategies and middleware to restrict access.
RBAClogic to authorize user with specific roles to use the endpoints.
Sendgridemail service support with sendgrid.
Error Handlingerrors custom middleware and helpers globally configured
MulterFile uploading configured to use in routes as middleware
Google Cloud Storagemiddleware configured to use Google Cloud Storage as upload bucket
Google Cloud Pub/Subpub/sub support for event driven events added
Axiosglobally configured in./src/utils/api.utils.js
Swaggerdocumentation reachable athttp://localhost:3000/api/v1/docs
Jesttesting tool support
Winstonlogger tool support
Dockerready configuration with multi-stage option
Best practicesin naming files
- 
Appentry point is located in./src/app.js
- 
Serverconfig entrypoint is located in./src/bin/www.js
- 
Babelconfig to transpile the code is located at./.babelrc
- 
Prettierconfig is located at./.prettierrc.yml
- 
Eslintconfig is located at./.eslintrc
- 
Routesconfig entrypoint is located in./src/routes/v1/index.route.js
- 
Passportconfig is located at./src/config/passport.config.js- Local Strategy is defined in ./src/services/passport/passport-local.service.js
- Google Strategy is defined in ./src/services/passport/passport-google.service.js
 
- Local Strategy is defined in 
- 
RBAClogic middleware is located at./src/middlewares/verifyRights.middleware.js- Roles configuration is located at ./src/config/roles.config.js
 
- Roles configuration is located at 
- 
Sendgridservice support is located at./src/services/email/sendgrid.service.js- You can define your own email services in this file
 
- 
MongoDBconfig is located at./src/config/mongodb.config.js- Models definition are located in ./src/services
 
- Models definition are located in 
- 
ErrorHandling middleware is located at./src/middlewares/errorHandler.middleware.js- You can configure as many errors you need in ./src/helpers/errors.helper.js
 
- You can configure as many errors you need in 
- 
Multermiddleware is located at./src/middlewares/upload.middleware.js- If you want to use Google Cloud Storage as upload bucket follow instructions at ./src/config/gcloud/README.md
 
- If you want to use Google Cloud Storage as upload bucket follow instructions at 
- 
Swaggerconfig file is located at./swagger.json- Swagger routes are defined in ./src/routes/swagger.route.js
 
- Swagger routes are defined in 
- 
Dockerconfig is located at./Dockerfile
- 
JESTtests are located in./src/tests/*
- 
Pub/Subservice is located at./src/services/pubsub/pub-sub.service.js- The pub/sub logic routes is located at ./src/routes/v1/events/*
- The pub/sub logic controller is located at ./src/controllers/events/*
 
- The pub/sub logic routes is located at 
src/
bin/- server configuration folder
config/- this folder contains all the configs file (database, passport, etc...)
constants/- this folder contains all the global constants
controllers/- all the controllers to use in routes that interact with services
debug/- the logger file will be stored here
helpers/- some helpers func i.e. an error helper that returns json everytime an error comes in
middlewares/- here you can find all the custom middlewares
models/- database model definition
routes/- here you find all the defined routes of the app
services/- here we store all the services; i.e. here we define methods to manipulate a db model entity
tests/- here we store all the jest test
utils/- containing some utils function to be reused in the code (i.e. axios global configuration)
Copy the .env.example to .env
cp env.example .envThen replace:
- MONGO_URIstring with your Mongo connection- MONGO_URI_TESTstring with your Mongo Test connection
 
- GOOGLE_APPLICATION_CREDENTIALSpath with yours
- GOOGLE_PROJECT_IDwith yours
- SENDGRID_API_KEYwith yours
- SENDGRID_SENDER_EMAILwith yours
In order to Google Cloud Storage works follow instructions located in
./src/config/gcloud/README.md
To get started with this repo npm install in the root folder
npm installTo getting started with a dev environment. Here we use nodemon and babel-node to restart the server asa we change something
npm run start:devTo transpile the code and create a production build
npm run transpileThis command will create a build in the root directory
To start with a production ready build you can run this command
# This set the NODE_ENV to production, npm-run-all, create a build and run the server command
npm run startIf you have a build and you want to node the build you can run
# This command launch the node instance inside the ./build/bin/www
npm run server# To launch all the tests that are in the tests folder
npm run testIf you use Docker and wanna dockerize the app you can run the command
docker build -t <dockerhubusername>/<docker-image-name>:<tag> .then
docker run --name <docker-process-name> -d - p 3000:3000 <dockerhubusername>/<docker-image-name>:<tag>