expresso with Sequelize
Feature
- TypeScript
v4.x
- Sequelize ORM
v6.x
Sequelize TypeScriptv2.x
- Nodemailer
v6.x
- Handlebars for templating HTML
- Yup for validation schema
v0.32.x
- JavaScript Style Standard with TypeScript
- Formating code using Prettier Integration Eslint and TypeScript Eslint
- Using Module Alias for simplify the require/import paths
- Documentation with Swagger
- Generate Log File with Winston
- Convensional Commit with Husky & Commitlint
Check Full Documentation
How to use
clone this repo with https
/ ssh
/ github cli
git clone https://github.com/masb0ymas/expresso.git
After cloning this repo, make sure you have duplicated
the .env.example
file to .env
, don't let the .env.example file be deleted or renamed.
Install
yarn
Enabled Husky
npx husky install
yarn husky install
Generate Secret Key
yarn key:generate
Usage Development
yarn dev
Lint Check
yarn test:lint
Type Check
yarn test:types
Type Check Watch mode
yarn test:types-watch
Build
by default build codebase with SWC
, if you want to build with TypeScript, run this command : yarn build:ts
yarn build
Using Sequelize
Using sequelize with development mode, you can set the database configuration in .env
, like this :
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=example_database
DB_USERNAME=example_user
DB_PASSWORD=example_password
DB_SYNC=
DB_TIMEZONE=+07:00
then after that you can adjust the database config in DB_DATABASE
, DB_USERNAME
, DB_PASSWORD
.
now you can run this command :
yarn db:reset
Usage Production
yarn serve:production
Usage PM2 for Cluster Process
pm2 start ecosystem.config.js --env=production
Config Nginx for Limiter / Node JS
server {
listen 80;
listen [::]:80;
server_name yourdomain.com;
client_max_body_size 2000M;
location / {
proxy_pass http://127.0.0.1:7000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
}
Run loadtest
npm install -g loadtest
Then run the app that you want to test with node app.js
. We’ll start by testing the version that doesn’t use clustering.
With the app running, open another Terminal and run the following load test:
loadtest http://localhost:8000/v1/user -n 1000 -c 100
-n
= network / requests
-c
= concurrency
--rps
= request per second
Read documentation loadtest
Result loadtest:
if you want to try 1000 requests
you have to increase RATE_LIMIT=1000
, by default 100 requests
Requests: 0 (0%), requests per second: 0, mean latency: 0 ms
Target URL: http://localhost:8000/v1/user
Max requests: 1000
Concurrency level: 100
Agent: none
Completed requests: 1000
Total errors: 0
Total time: 1.7057602980000002 s
Requests per second: 586
Mean latency: 162.8 ms
Percentage of the requests served within a certain time
50% 136 ms
90% 261 ms
95% 337 ms
99% 390 ms
100% 419 ms (longest request)
Run tests
yarn test
Run with Docker
before the first docker build, we first check IPv4 private
so that we can access the Database
outside the docker container
.
Adjust the config in .env like this:
...
DB_CONNECTION=mysql
DB_HOST=172.26.9.187 # example IPv4 private
DB_PORT=3306
DB_DATABASE=example
DB_USERNAME=your_username
DB_PASSWORD=your_password
DB_SYNC=
DB_TIMEZONE=+07:00
...
REDIS_HOST=172.26.9.187 # example IPv4 private
REDIS_PASSWORD=your_password
REDIS_PORT=6379
Building image docker
docker build . -t <your username>/expresso
Your image will now be listed by Docker:
$ docker images
# Example
REPOSITORY TAG ID CREATED
node 16 3b66eb585643 5 days ago
<your username>/expresso latest d64d3505b0d2 1 minute ago
Run Image
docker run -p 7000:8000 -d <your username>/expresso
Print the output of your app:
# Get container ID
$ docker ps
# Print app output
$ docker logs <container id>
# Example
Running on http://localhost:8080
If you need to go inside the container you can use the exec
command:
# Enter the container
$ docker exec -it <container id> /bin/bash
Release your version app
if you want to release the app version, you can use the following command :
yarn release
SMTP Basic
I use topol.io to create email templates, and it's free and can export to html format
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=465
MAIL_AUTH_TYPE=
[email protected]
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=
SMTP with Mailgun API
MAILGUN_API_KEY=your_api_key_mailgun
MAILGUN_DOMAIN=your_domain
SMTP Google Oauth Email ( Gmail )
MAIL_DRIVER=gmail
MAIL_HOST=
MAIL_PORT=
MAIL_AUTH_TYPE=OAuth2
[email protected]
MAIL_PASSWORD=
MAIL_ENCRYPTION=
OAUTH_CLIENT_ID=your_client_id
OAUTH_CLIENT_SECRET=your_client_secret
OAUTH_REDIRECT_URL=https://developers.google.com/oauthplayground
OAUTH_REFRESH_TOKEN=your_refresh_token
Author
Support Me
Show your support
Give a
This README was generated with