π A boilerplate for Node.js, Express, Mongoose, Heroku, Atlas, Nodemon, PM2, and Babel.
π Live Demo
This seed repository provides the following features:
- ---------- Essentials ----------
- Web application framework with Express.
- Object-document mapping with Mongoose.
- Make authenticated requests with Passport.
- File upload with Multer.
- Real-time communication with WS.
- ---------- Tools ----------
- Next generation JavaScript with Babel.
- JavaScript static code analyzer with ESLint.
- Code formatter with Prettier.
- Unit testing with Jest.
- End-to-End testing with Supertest.
- Mocking external requests with Nock.
- Automatically restart application with Nodemon.
- Keeping application alive with PM2.
- Reverse proxy with Caddy.
- ---------- Environments ----------
- Cloud application hosting with Heroku.
- Cloud NoSQL database hosting with Atlas.
- Cloud storageβ hosting with Cloudinary.
- Error tracking service with Sentry.
- Software container with Docker.
- Continuous integration with CircleCI.
- Fix and prevent known vulnerabilities with Snyk.
- Test coverage integration with Codecov.
Follow steps to execute this boilerplate.
- Clone this boilerplate
$ git clone --depth 1 https://github.com/Shyam-Chen/Express-Starter.git <PROJECT_NAME>
$ cd <PROJECT_NAME>
- Install dependencies
$ npm install
- Start a development server
$ yarn serve
- Produce a production-ready bundle
$ yarn build
- Lint and fix files
$ yarn lint
- Run unit tests
$ yarn unit
- Run end-to-end tests
$ yarn e2e
- MongoDB
$ brew tap mongodb/brew
$ brew install mongodb-community
$ mongo --version
# MongoDB shell version v4.4.1
# Build Info: {
# "version": "4.4.1",
# "gitVersion": "ad91a93a5a31e175f5cbf8c69561e788bbc55ce1",
# "modules": [],
# "allocator": "system",
# "environment": {
# "distarch": "x86_64",
# "target_arch": "x86_64"
# }
# }
# Starting MongoDB
$ brew services run mongodb-community
$ brew services list
# Stopping MongoDB
$ brew services stop mongodb-community
Dockerize an application.
- Build and run the container in the background
$ docker-compose up -d app
- Run a command in a running container
$ docker-compose exec app <COMMAND>
- Remove the old container before creating the new one
$ docker-compose rm -fs
- Restart up the container in the background
$ docker-compose up -d --build app
Local Databases
$ docker-compose up -d mongodb
Control the environment.
Set your local environment variables.
// src/env.js
export const NODE_ENV = process.env.NODE_ENV || 'development';
export const INDEX_NAME = process.env.INDEX_NAME || 'local';
export const HOST = process.env.HOST || '0.0.0.0';
export const PORT = process.env.PORT || 3000;
export const SECRET_KEY = process.env.SECRET_KEY || 'jbmpHPLoaV8N0nEpuLxlpT95FYakMPiu';
export const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/test';
export const REDIS_URL = process.env.REDIS_URL || 'redis://127.0.0.1:6379/4';
// ---
export const CLOUDINARY_URL = process.env.CLOUDINARY_URL || 'cloudinary://key:secret@domain_name';
export const RATE_LIMIT = process.env.RATE_LIMIT || 0;
export const SENTRY_DSN = process.env.SENTRY_DSN || null;
Add environment variables to the CircleCI build.
# Project Settings > Environment Variables > Add Environment Variable
SECRET_KEY
MONGODB_URI
SENTRY_DSN
The structure follows the LIFT Guidelines.
.
βββ src
β βββ core
β β βββ ...
β βββ <FEATURE> -> feature modules
β β βββ __tests__
β β β βββ controller.spec.js
β β β βββ service.spec.js
β β β βββ model.spec.js
β β β βββ rest|<FLOW>.e2e-spec.js
β β βββ controller.js
β β βββ service.js
β β βββ model.js
β β βββ index.js
β βββ <GROUP> -> module group
β β βββ <FEATURE> -> feature modules
β β βββ __tests__
β β β βββ controller.spec.js
β β β βββ service.spec.js
β β β βββ model.spec.js
β β β βββ rest|<FLOW>.e2e-spec.js
β β βββ controller.js
β β βββ service.js
β β βββ model.js
β β βββ index.js
β βββ app.js
β βββ env.js
β βββ server.js
βββ .editorconfig
βββ .eslintrc
βββ .gitignore
βββ .prettierrc
βββ babel.config
βββ Caddyfile
βββ circle.yml
βββ docker-compose.yml
βββ Dockerfile
βββ jest.config.js
βββ LICENSE
βββ package-lock.json
βββ package.json
βββ processes.js
βββ README.md
Microservice architecture β a variant of the service-oriented architecture structural style β arranges an application as a collection of loosely coupled services. In a microservices architecture, services are fine-grained and the protocols are lightweight.
See Server-side Micro-Fullstack for instructions on how to create microservices from source code.