Shyam-Chen / Express Starter
Programming Languages
Projects that are alternatives of or similar to Express Starter
Express Starter
π A boilerplate for Node.js, Express, Mongoose, Heroku, Atlas, Nodemon, PM2, and Babel.
π Live Demo
This seed repository provides the following features:
- ---------- Essentials ----------
- [x] Web application framework with Express.
- [x] Object-document mapping with Mongoose.
- [x] Make authenticated requests with Passport.
- [x] File upload with Multer.
- [x] Real-time communication with WS.
- ---------- Tools ----------
- [x] Next generation JavaScript with Babel.
- [x] JavaScript static code analyzer with ESLint.
- [x] Code formatter with Prettier.
- [x] Unit testing with Jest.
- [x] End-to-End testing with Supertest.
- [x] Mocking external requests with Nock.
- [x] Automatically restart application with Nodemon.
- [x] Keeping application alive with PM2.
- [x] Reverse proxy with Caddy.
- ---------- Environments ----------
- [x] Cloud application hosting with Heroku.
- [x] Cloud NoSQL database hosting with Atlas.
- [x] Cloud storageβ hosting with Cloudinary.
- [x] Error tracking service with Sentry.
- [x] Software container with Docker.
- [x] Continuous integration with CircleCI.
- [x] Fix and prevent known vulnerabilities with Snyk.
- [x] Test coverage integration with Codecov.
Table of Contents
Getting Started
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
Dockerization
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
Configuration
Control the environment.
Default environments
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:[email protected]_name';
export const RATE_LIMIT = process.env.RATE_LIMIT || 0;
export const SENTRY_DSN = process.env.SENTRY_DSN || null;
Continuous integration environments
Add environment variables to the CircleCI build.
# Project Settings > Environment Variables > Add Environment Variable
SECRET_KEY
MONGODB_URI
SENTRY_DSN
Examples
Directory Structure
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
Microservices
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.