Skip to content

RobbeCl/boilerplate-express-typescript-sequelize

 
 

Repository files navigation

Welcome to boilerplate-express-typescript-sequelize 👋

Version Documentation Maintenance License: MIT

Just Boilerplate Express with TypeScript ( 🦊 )

Prerequisites

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

Feature

How to use

clone this repo with https / ssh / github cli

git clone https://github.com/masb0ymas/boilerplate-express-typescript-sequelize.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 Jwt Secret

npm run refresh:env-jwt

or

yarn refresh:env-jwt

Usage Development

npm run dev

or

yarn dev

Type Check

npm run type-check

or

yarn type-check

Type Check Watch mode

npm run type-check:watch

or

yarn type-check:watch

Build

Recommended using build with Babel, build with TS is still unstable

npm run build:babel

or

yarn build:babel

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

if you set production mode change the database config PROD_DB_DATABASE

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

Run tests

npm run test

or

yarn test

Run with Docker

Adjust the config in .env like this:

...

PORT=7000 # 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

...

PROD_DB_CONNECTION=mysql
PROD_DB_HOST=db
PROD_DB_PORT=3306
PROD_DB_DATABASE=example
PROD_DB_USERNAME=your_username
PROD_DB_PASSWORD=your_password
PROD_DB_OPERATOR_ALIAS=
PROD_DB_TIMEZONE=+07:00

...

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=your_password
REDIS_PORT=6380 # Default: 6379

container_name in each service is customizable.

PORT=... If you want to use a port other than 7000, 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:
      - '7000:7000'

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: ${PROD_DB_PASSWORD}
    MYSQL_DATABASE: ${PROD_DB_DATABASE}
    MYSQL_USER: ${PROD_DB_USERNAME}
    MYSQL_PASSWORD: ${PROD_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=null

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=null
MAIL_PORT=null
MAIL_AUTH_TYPE=OAuth2
[email protected]
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

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

About

Just Boilerplate Express, Sequelize and TypeScript ( 🦊 )

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 69.9%
  • HTML 16.4%
  • JavaScript 12.4%
  • Shell 0.7%
  • Dockerfile 0.3%
  • Pug 0.2%
  • CSS 0.1%