Giter Club home page Giter Club logo

yaredtsy / express-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shyam-chen/express-starter

0.0 0.0 0.0 6.1 MB

:truck: A boilerplate for Node.js, Express, Mongoose, Heroku, Atlas, Nodemon, PM2, and Babel. REST / GraphQL API Server | PaaS | SaaS | CI/CD | Jest | Supertest | Docker | MongoDB | PostgreSQL | Sequelize | Lodash | RxJS | JWT | Passport | WebSocket | Redis | CircleCI | Apollo | DevSecOps | Microservices | Backend Starter Kit | ES6 | ESM

License: MIT License

JavaScript 98.26% Dockerfile 1.74%

express-starter's Introduction

Express Starter

๐Ÿšš A boilerplate for Node.js, Express, Mongoose, Heroku, Atlas, Nodemon, PM2, and Babel.

Build Status Coverage Status

๐ŸŒˆ 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.

Performance (Fastify)

Table of Contents

Project Setup

Follow steps to execute this boilerplate.

Install dependencies

$ npm install

Start a development server

$ brew services start mongodb-community
$ yarn serve

Produce a production-ready bundle

$ yarn build

Lints and fixes files

$ yarn lint

Runs unit tests

Files: src/**/*.spec.js

$ yarn unit

Runs end-to-end tests

Files: e2e/**/*.spec.js

# Before running the `meas` command, make sure to run the following commands.
$ yarn build
$ yarn preview

# If it's not setup, run it.
$ yarn setup

$ yarn e2e

Measures APIs

Files: e2e/**/*.meas.js

# Before running the `meas` command, make sure to run the following commands.
$ yarn build
$ yarn preview

# If it's not setup, run it.
$ yarn setup

$ yarn meas

Mocks third-party APIs

# If it's not active, run it.
$ yarn active

$ yarn mock

Dockerization

Dockerize an application.

  1. Build and run the container in the background
$ docker-compose up -d mongodb app
  1. Run a command in a running container
$ docker-compose exec app <COMMAND>
  1. Remove the old container before creating the new one
$ docker-compose rm -fs
  1. Restart up the container in the background
$ docker-compose up -d --build app

Configuration

Control the environment.

Default environments

Set your local environment variables. (use export const <ENV_NAME> = process.env.<ENV_NAME> || <LOCAL_ENV>;)

// 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 FACEBOOK_APP_ID = process.env.FACEBOOK_APP_ID || 'XXX';
export const FACEBOOK_APP_SECRET = process.env.FACEBOOK_APP_SECRET || 'XXX';

export const GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID || 'XXX';
export const GOOGLE_CLIENT_SECRET = process.env.GOOGLE_CLIENT_SECRET || 'XXX';

export const APPLE_SERVICES_ID = process.env.APPLE_SERVICES_ID || 'XXX';
export const APPLE_TEAM_ID = process.env.APPLE_TEAM_ID || 'XXX';
export const APPLE_KEY_ID = process.env.APPLE_KEY_ID || 'XXX';
export const APPLE_PRIVATE_KEY = process.env.APPLE_PRIVATE_KEY || 'XXX';

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;

Continuous integration environments

Add environment variables to the CircleCI build.

# Project Settings > Environment Variables > Add Environment Variable

SECRET_KEY
MONGODB_URI
CLOUDINARY_URL
SENTRY_DSN

File-based environments

If you want to set environment variables from a file.

.
โ”œโ”€โ”€ e2e
โ”œโ”€โ”€ envs
โ”‚   โ”œโ”€โ”€ dev.js
โ”‚   โ”œโ”€โ”€ stage.js
โ”‚   โ””โ”€โ”€ prod.js
โ”œโ”€โ”€ mock
โ””โ”€โ”€ src
// envs/<ENV_NAME>.js

function Environment() {
  this.NODE_ENV = 'production';
  // more...
}

module.exports = new Environment();
$ npm install babel-plugin-transform-inline-environment-variables env-cmd -D
// babel.config.js

    plugins: [
      // ...
      'transform-inline-environment-variables',
    ],
// package.json

  "scripts": {
    // "env-cmd -f ./envs/<ENV_NAME>.js" + "yarn build"
    "build:dev": "env-cmd -f ./envs/dev.js yarn build",
    "build:stage": "env-cmd -f ./envs/stage.js yarn build",
    "build:prod": "env-cmd -f ./envs/prod.js yarn build",
  },

Examples

Directory Structure

The structure follows the LIFT Guidelines.

.
โ”œโ”€โ”€ e2e
โ”œโ”€โ”€ mock
โ”‚   โ”œโ”€โ”€ requests
โ”‚   โ””โ”€โ”€ responses
โ”œโ”€โ”€ src
โ”‚   โ”œโ”€โ”€ core
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ <FEATURE> -> feature modules
โ”‚   โ”‚   โ”œโ”€โ”€ __tests__
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ controller.spec.js
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ service.spec.js
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ model.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
โ”‚   โ”‚       โ”œโ”€โ”€ controller.js
โ”‚   โ”‚       โ”œโ”€โ”€ service.js
โ”‚   โ”‚       โ”œโ”€โ”€ model.js
โ”‚   โ”‚       โ””โ”€โ”€ index.js
โ”‚   โ”œโ”€โ”€ app.js
โ”‚   โ”œโ”€โ”€ env.js
โ”‚   โ””โ”€โ”€ server.js
โ”œโ”€โ”€ .editorconfig
โ”œโ”€โ”€ .eslintrc
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ .prettierrc
โ”œโ”€โ”€ babel.config
โ”œโ”€โ”€ Caddyfile
โ”œโ”€โ”€ circle.yml
โ”œโ”€โ”€ develop.Dockerfile
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ jest.config.js
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ package-lock.json
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ processes.js
โ”œโ”€โ”€ produce.Dockerfile
โ””โ”€โ”€ 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.

express-starter's People

Contributors

dependabot[bot] avatar shyam-chen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.