This is a minimalist express boilerplate with the following features:
ECMA Script 2020
or ES2020 features enabledBabel
to transpile the js codeDotenv
Load environment variables from .env fileEslint
Code quality toolPrettier
to prettify the codeMongoDB
ready to go configuration with mongooseCORS
feature enabledPassport
authentication strategies and middleware to restrict access.RBAC
logic to authorize user with specific roles to use the endpoints.Sendgrid
email service support with sendgrid.Error Handling
errors custom middleware and helpers globally configuredMulter
File uploading configured to use in routes as middlewareGoogle Cloud Storage
middleware configured to use Google Cloud Storage as upload bucketGoogle Cloud Pub/Sub
pub/sub support for event driven events addedAxios
globally configured in./src/utils/api.utils.js
Swagger
documentation reachable athttp://localhost:3000/api/v1/docs
Jest
testing tool supportWinston
logger tool supportDocker
ready configuration with multi-stage optionBest practices
in naming files
App
entry point is located in ./src/app.js
Server
config entrypoint is located in ./src/bin/www.js
Babel
config to transpile the code is located at ./.babelrc
Prettier
config is located at ./.prettierrc.yml
Eslint
config is located at ./.eslintrc
Routes
config entrypoint is located in ./src/routes/v1/index.route.js
Passport
config is located at ./src/config/passport.config.js
./src/services/passport/passport-local.service.js
./src/services/passport/passport-google.service.js
RBAC
logic middleware is located at ./src/middlewares/verifyRights.middleware.js
./src/config/roles.config.js
Sendgrid
service support is located at ./src/services/email/sendgrid.service.js
MongoDB
config is located at ./src/config/mongodb.config.js
./src/services
Error
Handling middleware is located at ./src/middlewares/errorHandler.middleware.js
./src/helpers/errors.helper.js
Multer
middleware is located at ./src/middlewares/upload.middleware.js
./src/config/gcloud/README.md
Swagger
config file is located at ./swagger.json
./src/routes/swagger.route.js
Docker
config is located at ./Dockerfile
JEST
tests are located in ./src/tests/*
Pub/Sub
service is located at ./src/services/pubsub/pub-sub.service.js
./src/routes/v1/events/*
./src/controllers/events/*
src/
bin/
- server configuration folderconfig/
- this folder contains all the configs file (database, passport, etc...)constants/
- this folder contains all the global constantscontrollers/
- all the controllers to use in routes that interact with servicesdebug/
- the logger file will be stored herehelpers/
- some helpers func i.e. an error helper that returns json everytime an error comes inmiddlewares/
- here you can find all the custom middlewaresmodels/
- database model definitionroutes/
- here you find all the defined routes of the appservices/
- here we store all the services; i.e. here we define methods to manipulate a db model entitytests/
- here we store all the jest testutils/
- containing some utils function to be reused in the code (i.e. axios global configuration)
Copy the .env.example to .env
cp env.example .env
Then replace:
MONGO_URI
string with your Mongo connection
MONGO_URI_TEST
string with your Mongo Test connectionGOOGLE_APPLICATION_CREDENTIALS
path with yoursGOOGLE_PROJECT_ID
with yoursSENDGRID_API_KEY
with yoursSENDGRID_SENDER_EMAIL
with yoursIn 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 install
To getting started with a dev environment. Here we use nodemon and babel-node to restart the server asa we changesomething
npm run start:dev
To transpile the code and create a production build
npm run transpile
This 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 start
If 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 test
If 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>
Express Boilerplate ExpressJS boilerplate with Socket.IO, Mongoose for scalable projects. Includes ExpressJS NodeJS Mongoose Socket.io Nodemon API-Docs Getting Started These instructions will get you
Express, React/Redux, MySQL Boilerplate Get Started 1. Prerequisites NodeJs NPM - Node package manager MySQL - Relational database management system (RDBMS) 2. Installation On the command prompt run t
express-graphql-boilerplate Express GraphQL API with JWT Authentication and support for sqlite, mysql, and postgresql Authentication via JWT Support for sqlite, mysql, and postgresql Support for graph
Express ES2017 REST API Boilerplate Boilerplate/Generator/Starter Project for building RESTful APIs and microservices using Node.js, Express and MongoDB Features No transpilers, just vanilla javascrip
Express MVC Boilerplate A simple mvc boilerplate for express.js (gulp + expressjs + nodemon + browser-sync) Related modules express - web application framework for node pug - template engine stylus -
Foreword This is a boilerplate to help quickly throw up "internal use / private" style semi-secure REST api's. It comes packaged with Mongoose, express, helmet, and a whole host of security features.