Skip to content

TranBaVinhSon/microservice_nodejs_template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

46 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Microservice Nodejs Template

Prettier Lerna Documentation License: MIT

Lerna + Docker + Typescript + EsLint + Prettier

Table of Contents

Introduction

The simple project shows how to setup monorepo by Typescript + Docker + Lerna + Eslinter + Prettier.

The project has 3 packages (inside packages directory)

  • api_gateway (http server)
  • backend (http server)
  • base (shared package between api_gateway and backend)

Note: Each package has its own eslint, tsconfig, preitter config.

Techstack

  • Lerna - A tool for managing JavaScript projects with multiple packages
  • TsED - A TypeScript Framework on top of Express
  • Docker
  • Eslint + Prettier

Install

make install-all

That's it πŸš€

Usage

Go to root project: cd microservice_nodejs_template

Running project

docker-compose up

That's it πŸš€

After run docker-compose up, you will see api_gateway container runs on 3000 port. and backend container runs on 8000 port.

(you can also check the api by make a request to GET localhost:3000/api/v1/users/)

Screen Shot 2019-12-07 at 4 14 47 PM

Compile ts to js

  • Compile all packages
npm run build
  • Compile api_gateway package
npm run build:api_gateway
  • Compile backend package
npm run build:backend
  • Compile base package
npm run build:base

Running Eslint

  • Running Eslint on all packages
npm run eslint

Project Structure

Each package under the packages folder.

microservice_nodejs_template
β”œβ”€β”€ docker/
β”‚   β”œβ”€β”€ api_gateway/
β”‚   β”‚   └── Dockerfile
β”‚   β”œβ”€β”€ backend/
β”‚   β”‚   └── Dockerfile
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ api_gateway/
β”‚   β”‚   └── src/
β”‚   β”‚   β”œβ”€β”€ package.json
β”‚   β”‚   β”œβ”€β”€ tsconfig.json
β”‚   β”‚
β”‚   β”œβ”€β”€ backend/
β”‚   β”‚   └── src/
β”‚   β”‚   └── package.json
β”‚   β”‚   β”œβ”€β”€ tsconfig.json
β”‚   β”‚
β”‚   β”œβ”€β”€ base/
β”‚   β”‚   └── src/
β”‚   β”‚   └── package.json
β”‚   β”‚   β”œβ”€β”€ tsconfig.json
β”‚
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ package.json
β”œβ”€β”€ lerna.json
β”œβ”€β”€ README.md

api_gateway container structure

microservice_nodejs_template
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ api_gateway/
β”‚   β”‚   └── src/
β”‚   β”‚   β”œβ”€β”€ package.json
β”‚   β”‚   β”œβ”€β”€ tsconfig.json
β”‚   β”‚
β”‚   β”œβ”€β”€ base/
β”‚   β”‚   └── src/
β”‚   β”‚   └── package.json
β”‚   β”‚   β”œβ”€β”€ tsconfig.json
β”‚
β”‚
β”œβ”€β”€ package.json
β”œβ”€β”€ lerna.json

backend container structure

microservice_nodejs_template
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ backend/
β”‚   β”‚   └── src/
β”‚   β”‚   β”œβ”€β”€ package.json
β”‚   β”‚   β”œβ”€β”€ tsconfig.json
β”‚   β”‚
β”‚   β”œβ”€β”€ base/
β”‚   β”‚   └── src/
β”‚   β”‚   └── package.json
β”‚   β”‚   β”œβ”€β”€ tsconfig.json
β”‚
β”‚
β”œβ”€β”€ package.json
β”œβ”€β”€ lerna.json

Contributing

Contributions, issues and feature requests are welcome.