Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sonufrienko/microservice
Ready to use Node.js microservice
https://github.com/sonufrienko/microservice
Last synced: 6 days ago
JSON representation
Ready to use Node.js microservice
- Host: GitHub
- URL: https://github.com/sonufrienko/microservice
- Owner: sonufrienko
- License: mit
- Created: 2018-12-26T12:29:40.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T18:22:55.000Z (almost 2 years ago)
- Last Synced: 2024-10-16T05:35:08.192Z (22 days ago)
- Language: JavaScript
- Homepage:
- Size: 2.06 MB
- Stars: 157
- Watchers: 8
- Forks: 43
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![](microservice.png)
# Ready to use Node.js microservice
## Features
- **Framework**: Express
- **Authentication**: JWT with public/private key file
- **Database**: MongoDB (Native), PostgreSQL (Sequelize)
- **Code**: ESLint, Prettier, Husky
- **Debuging**: Debug, VS Code configurations
- **Logging**: Winston
- **Testing**: Jest, SuperTest, AutoCannon
- **Continuous Integration**: GitHub Actions + Docker Compose
- **Other**: PM2, DotEnv
- Well structured
- API versioning
- Request Validation## Getting Started
```shell
git clone https://github.com/sonufrienko/microservice
cd microservice# Create environment variables from example
mv .env.example .env# Generate JWT keys
ssh-keygen -t rsa -b 2048 -q -N '' -m PEM -f private.key \
&& rm private.key.pub \
&& openssl rsa -in private.key -pubout -outform PEM -out public.key# Install all dependencies
npm install# Run on port 4000
npm start
```## Running SQL database migrations
```shell
npx sequelize db:migrate
```## Start with PM2
```shell
pm2 start process.json
```## Start with Docker
```shell
# Generate JWT keys
ssh-keygen -t rsa -b 2048 -q -N '' -m PEM -f private.key \
&& rm private.key.pub \
&& openssl rsa -in private.key -pubout -outform PEM -out public.key# Build image
docker build -t app/microservice:v1 .# Run on port 4000
docker run -p 4000:4000 -d --name microservice app/microservice:v1# Run on host network
docker run -d --name microservice --network=host app/microservice:v1
```## Environment variables
Name | Value
------------ | -------------
PORT|4000
LOG_LEVEL|info
DEBUG|*
MONGO_HOST|127.0.0.1
MONGO_PORT|27017
MONGO_DB|test
MONGO_USER|
MONGO_PASS|
MONGO_URL|
SQL_HOST|127.0.0.1
SQL_HOST_READ|127.0.0.1
SQL_HOST_WRITE|127.0.0.1
SQL_PORT|5432
SQL_DB|test
SQL_USER|postgres
SQL_PASS|
SQL_DIALECT|postgres
SQL_POOL_LIMIT|100## Structure
```
.
├── config # App configuration files
│ ├── sequelize.js # sequelize config
│ └── ... # Other configurations
├── db # Data access stuff
│ ├── migrations # Migrations
│ ├── models # Models
│ ├── seeds # Seeds
│ └── mongo.js # MongoDB instantiation
│ └── sequelize.js # Sequelize (PostgresSQL/MySQL) instantiation
├── docs # Documentation
├── helpers # Helpers (formats, validation, etc)
├── routes
│ ├── controllers # Request managers
│ ├── middlewares # Request middlewares
│ └── routes.js # Define routes and middlewares here
├── scripts # Standalone scripts for dev uses
├── services # External services implementation
│ ├── serviceOne
│ └── serviceTwo
├── tests # Testing
├── .env # Environment variables
├── .sequelizerc # Sequelize CLI config
├── app.js # App starting point
├── Dockerfile # Dockerfile
├── process.json # pm2 init
├── package.json
├── private.key # Sign tokens
├── public.key # Validate tokens
└── README.md
```