Giter Site home page Giter Site logo

zhouyiran7 / expresso Goto Github PK

View Code? Open in Web Editor NEW

This project forked from masb0ymas/expresso-sequelize

0.0 0.0 0.0 6.94 MB

expresso ☕ ( express + TypeScript + Sequelize )

License: MIT License

JavaScript 20.10% TypeScript 65.85% Dockerfile 0.39% Shell 0.40% HTML 13.26%

expresso's Introduction

expresso

( Express TS Sequelize )


version Node TypeScript Express documentation maintenance License: MIT

Just Boilerplate Express with TypeScript ( 🦊 )

Prerequisites

  • npm >= v6.x
  • node >= v12.x
  • eslint v7.x
  • husky >= v7.x
  • Familiar with TypeScript 💪

Feature

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

npm install

or

yarn

Enabled Husky

npx husky install

or

yarn husky install

Generate Secret Key

npm run key:generate

or

yarn key:generate

Usage Development

npm run dev

or

yarn dev

Type Check

npm run test:types

or

yarn test:types

Type Check Watch mode

npm run test:types-watch

or

yarn test:types-watch

Build

npm run build

or

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_OPERATOR_ALIAS=
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 :

npm run db:reset

or

yarn db:reset

Usage Production

npm run serve:production

or

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

npm run test

or

yarn test

Run with Docker

Adjust the config in .env like this:

...

PORT=8000 # change this port according to your needs

...

DB_CONNECTION=mysql
DB_HOST=db # access to service db in docker
DB_PORT=3306
DB_DATABASE=example
DB_USERNAME=your_username
DB_PASSWORD=your_password
DB_OPERATOR_ALIAS=
DB_TIMEZONE=+07:00

...

REDIS_HOST=redis # access to service redis in docker
REDIS_PASSWORD=your_password
REDIS_PORT=6379

container_name in each service is customizable.

PORT=... If you want to use a port other than 8000, you must also change the port in the services app

services:
  app:
    build:
      context: .
    container_name: express_app
    depends_on:
      - db
      - redis
    restart: always
    ports:
      - '8000:8000'

DB_HOST=... must be accessed using IPv4 Docker Network services db.

db:
  image: mariadb
  container_name: express_db
  volumes:
    - ./storage/mariadb-volume:/var/lib/mysql
  environment:
    MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
    MYSQL_DATABASE: ${DB_DATABASE}
    MYSQL_USER: ${DB_USERNAME}
    MYSQL_PASSWORD: ${DB_PASSWORD}
  restart: always
  ports:
    - '3307:3306'
  networks:
    - express_network

After all the above configuration is adjusted, you can run it with the command:

Command aggregates the output of each container

docker-compose up

Detached mode: Run containers in the background,

docker-compose up -d

Release your version app

if you want to release the app version, you can use the following command :

npm run release

or

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

Setup Google Oauth

Author

👤 masb0ymas

Support Me

ko-fi

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator

expresso's People

Contributors

chornos13 avatar dependabot-preview[bot] avatar dependabot[bot] avatar masb0ymas avatar snyk-bot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.