nodecube
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
- nodecube-cli: TODO
- nodecube-example: Boilerplate + demo https://github.com/dexteryy/nodecube-example/
Features
- TODO
Integration
- Express
- graphql-tools [TODO] / graphql-server-express [TODO] + graphql-anywhere [TODO]
- gRPC [TODO]
- mongoose + sequelize + ioredis + aws-sdk-js [TODO] + aliyun-sdk
- nodemailer
- uuid + shortid + bcrypt + spark-md5
- Docker + Docker Compose
- Babel v6
- ESLint v2 (babel + react + flowtype [TODO] + graphql [TODO] + fp [TODO]) + Flow
- AVA [TODO] / Mocha & Chai + supertest + nock + Sinon.JS + faker.js
- dotenv + Plop [TODO] (Handlebar + Inquirer) + Commitizen (cz-conventional-changelog) + Husky + EditorConfig
Boilerplate as library:
httpService
- exampleerrorTrigger
+errorResponse
- examplelogger
mongo
/rds
/redis
/oss
- exampleauthorization
- example
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
- ... - See
- data/ -
- mongo/ - Initial data for MongoDB container
test_data.json
- mysql/ - Initial data for MySQL container
test_data.sql
- mongo/ - Initial data for MongoDB container
- 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/
connectServices.js
- All external services needed to be connected
index.js
- Theserver
object and HTTPservice
object generated by nodecube'shttpService
factory
- common/ - Reusable code
server.js
- Load environment variables fromenv.config
env.config
- Project-defined configuration options for nodecube and project codepackage.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