WanChengCheng / nodecube

A batch of continuously updated base code and configurations for the minimal modern node.js service that conform to RESTful API, 12-Factor App, Microservice Architecture

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nodecube

NPM Version Build Status Dependencies Status Greenkeeper badge

Nodei

nodecube is a batch of continuously updated base code and configurations for the minimal modern Node.js service that conform to RESTful API, 12-Factor App, Microservice Architecture

Features

  • TODO

Integration

Boilerplate as library:

How to create an API service project

Step 1

Use nodecube-cli (TODO) or imitate the nodecube-example to create the minimal structure and configure files:

  • configs/ - Project-defined configuration files and build scripts
    • ... - See Step 2
  • data/ -
    • mongo/ - Initial data for MongoDB container
      • test_data.json
    • mysql/ - Initial data for MySQL container
      • test_data.sql
  • server/ - All source code
    • common/ - Reusable code
      • model/
      • utils/
      • ...
    • api/ - Express Routers for API requests
      • common/ - Reusable code shared between feature sets
      • feature1/ - A feature set
        • index.js
        • index.spec.js
      • feature2/ - A feature set
      • ...
      • index.js
    • utils/
    • index.js - The server object and HTTP service object generated by nodecube's httpService factory
  • server.js - Load environment variables from env.config
  • env.config - Project-defined configuration options for nodecube and project code
  • package.json - Minimal dependencies and npm scripts based on ndoecube
  • ... - See Step 2
  • .eslintrc.yml
  • .editorconfig

Step 2

Add the project-defined template file for env.config

cp ./node_modules/nodecube/configs/env.sample.config ./configs/

Add the Dockerfile only for production (or staging) environment

cp ./node_modules/nodecube/configs/Dockerfile ./

Add other configuration files depended by nodecube and recommended npm scripts

cp ./node_modules/nodecube/configs/babelrc ./.babelrc
cp ./node_modules/nodecube/configs/gitignore ./.gitignore
cp ./node_modules/nodecube/configs/dockerignore ./.dockerignore

Step 3

Generate your project-defined compose file (example) for development evironment, see Multiple Compose files

cp ./node_modules/nodecube/configs/docker-compose-dev.override.sample.yml ./configs/docker-compose-dev.override.yml
# This file may need to be modified to fit your needs (follow TODO comments)
vim ./configs/docker-compose-dev.override.yml

Optionally, generate the Dockerfile for mongoimport (for running mongoimport in the mongo container)

cp ./node_modules/nodecube/configs/Dockerfile-mongoimport.sample ./configs/Dockerfile-mongoimport
# This file must be modified to fit your needs
vim ./configs/Dockerfile-mongoimport

How to work with the API service project

Setup

cp configs/env.sample.config env.config

For developers in China:

cp ./node_modules/nodecube/configs/Dockerfile-china Dockerfile-dev

For other developers:

cp Dockerfile Dockerfile-dev

Install dependencies

yarn

Create or update containers for development environment

Remove all old containers and images, build new ones and run testing

npm run dev:rebuild

Just remove database containers and images

npm run dev:empty

Just remove all containers and images

npm run dev:reset

Update

Reinstall all dependencies and update lock file

npm run upgrade
npm run dev:rebuild

Local testing

npm run lint
npm run dev:test

Running in development environment

npm run dev
npm run dev:debug

Running in production (or staging) environment

Need a new docker-compose.yml with reconfigured environment variables

Continuous integration

Send pull request to master branch

Continuous deployment

Send pull request to production (or staging) branch

About

A batch of continuously updated base code and configurations for the minimal modern node.js service that conform to RESTful API, 12-Factor App, Microservice Architecture

License:MIT License


Languages

Language:JavaScript 80.2%Language:Shell 19.8%