🥚 A boilerplate for Node.js, Koa, Mongoose, Heroku, Atlas, Nodemon, PM2, and Babel.
Follow steps to execute this boilerplate.
$ yarn install
$ brew services start redis
$ brew services start mongodb-community
$ yarn serve
$ yarn build
$ yarn lint
Files: src/**/*.spec.js
$ yarn unit
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
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
# If it's not active, run it.
$ yarn active
$ yarn mock
Dockerize an application.
Control the environment.
Set your local environment variables. (use this.<ENV_NAME> = process.env.<ENV_NAME> || <LOCAL_ENV>;
)
// env.js
function Environment() {
this.NODE_ENV = process.env.NODE_ENV || 'development';
this.HOST_NAME = process.env.HOST_NAME || '0.0.0.0';
this.SITE_PORT = process.env.SITE_PORT || 3000;
this.SECRET_KEY = process.env.SECRET_KEY || 'SrScah0TXyRFyo7tqYBgmk9YgAPNGKXR';
this.REDIS_URL = process.env.REDIS_URL || 'redis://127.0.0.1:6379/4';
this.MONGODB_URI = process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/test';
this.CLOUDINARY_URL = process.env.CLOUDINARY_URL || 'cloudinary://key:secret@domain_name';
}
module.exports = new Environment();
Set Docker environment variables during image build. (see produce.Dockerfile
)
# envs --
ARG secret_key
ENV SECRET_KEY=$secret_key
ARG redis_url
ENV REDIS_URL=$redis_url
ARG mongodb_uri
ENV MONGODB_URI=$mongodb_uri
# -- envs
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';
this.HOST_NAME = '0.0.0.0';
this.SITE_PORT = 3000;
this.SECRET_KEY = 'SrScah0TXyRFyo7tqYBgmk9YgAPNGKXR';
this.REDIS_URL = 'redis://127.0.0.1:6379/4';
this.MONGODB_URI = 'mongodb://127.0.0.1:27017/test';
this.CLOUDINARY_URL = 'cloudinary://key:secret@domain_name';
}
module.exports = new Environment();
$ yarn add env-cmd -D
// 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",
},
- Hello World
- CRUD Operations
- Authentication
- File Uploads
- Realtime Data
.
├── e2e
├── mock
│ ├── requests
│ └── responses
├── src
│ ├── core
│ │ └── ...
│ ├── <FEATURE> -> feature module
│ │ ├── __tests__
│ │ │ ├── controller.spec.js
│ │ │ ├── service.spec.js
│ │ │ └── model.spec.js
│ │ ├── controller.js
│ │ ├── service.js
│ │ ├── model.js
│ │ └── index.js
│ ├── <GROUP> -> module group
│ │ └── <FEATURE> -> feature module
│ │ ├── __tests__
│ │ │ ├── controller.spec.js
│ │ │ ├── service.spec.js
│ │ │ └── model.spec.js
│ │ ├── controller.js
│ │ ├── service.js
│ │ ├── model.js
│ │ └── index.js
│ ├── app.js
│ └── server.js
├── .editorconfig
├── .eslintrc
├── .gitignore
├── .prettierrc
├── babel.config.js
├── build.js
├── Caddyfile
├── circle.yml
├── docker-compose.yml
├── Dockerfile
├── env.js
├── jest.config.js
├── LICENSE
├── package.json
├── README.md
├── webpack.config.js
└── yarn.lock
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.