Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kazi-naimul/typescript-express-mysql-boilerplate
A boilerplate for any enterprise rest api or service with Node.js-typescript, Express and Sequelize ORM for mysql, postgresql or others.
https://github.com/kazi-naimul/typescript-express-mysql-boilerplate
boilerplate express nodejs sequelize typescript
Last synced: 4 days ago
JSON representation
A boilerplate for any enterprise rest api or service with Node.js-typescript, Express and Sequelize ORM for mysql, postgresql or others.
- Host: GitHub
- URL: https://github.com/kazi-naimul/typescript-express-mysql-boilerplate
- Owner: kazi-naimul
- Created: 2022-06-17T17:20:18.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-24T07:52:01.000Z (11 months ago)
- Last Synced: 2024-04-18T14:09:07.217Z (7 months ago)
- Topics: boilerplate, express, nodejs, sequelize, typescript
- Language: TypeScript
- Homepage:
- Size: 94.7 KB
- Stars: 40
- Watchers: 3
- Forks: 14
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Boilerplate for Typescript-Express with sequelize ORM
A boilerplate for any enterprise rest api or service with Node.js -Typescript, Express and Sequelize ORM for mysql, postgresql or others.
By running this project you will get a production ready environment with all necessary supports for validation, unit testing, socket, redis and many more.This repo is the typescript version of my another boilerplate of [Nodejs Express Mysql boilerplate](https://github.com/kazi-naimul/node-express-mysql-boilerplate)
## Manual Installation
Clone the repo:
```bash
git clone https://github.com/kazi-naimul/typescript-express-mysql-boilerplate
cd typescript-express-mysql-boilerplate
```Install the dependencies:
```bash
yarn install
```Set the environment variables:
```bash
cp .env.example .env# open .env and modify the environment variables (if needed)
```## Features
- **ECMAScript Modules (ESM)**
- **ORM**: [Sequelize](https://sequelize.org/) orm for object data modeling
- **Migration and Seed**: DB migration and Seed using [Sequelize-CLI](https://github.com/sequelize/cli)
- **Authentication and authorization**: using [passport](http://www.passportjs.org)
- **Error handling**: centralized error handling
- **Validation**: request data validation using [Joi](https://github.com/hapijs/joi)
- **Logging**: using [winston](https://github.com/winstonjs/winston)
- **Testing**: unittests using [Mocha](https://mochajs.org/)
- **Caching**: Caching using [Redis](https://redis.io/)
- **Bidirectional Communication**: using [Scoket](https://socket.io/)
- **Job scheduler**: with [Node-cron](https://www.npmjs.com/package/node-cron)
- **Dependency management**: with [Yarn](https://yarnpkg.com)
- **Environment variables**: using [dotenv](https://github.com/motdotla/dotenv) and [cross-env](https://github.com/kentcdodds/cross-env#readme)
- **CORS**: Cross-Origin Resource-Sharing enabled using [cors](https://github.com/expressjs/cors)
- **Docker support**
- **Linting**: with [ESLint](https://eslint.org) and [Prettier](https://prettier.io)
- **Fast Compilation**: with [SWC](https://swc.rs/)## Commands
Running locally:
```bash
yarn start:dev
```Running in production:
```bash
yarn start
```Testing:
```bash
# run all tests
yarn test```
## Environment Variables
The environment variables can be found and modified in the `.env` file. They come with these default values:
```bash
#Server environment
NODE_ENV=development
#Port number
PORT=5000#Db configuration
DB_HOST=db-host
DB_USER=db-user
DB_PASS=db-pass
DB_NAME=db-name# JWT secret key
JWT_SECRET=your-jwt-secret-key
# Number of minutes after which an access token expires
JWT_ACCESS_EXPIRATION_MINUTES=5
# Number of days after which a refresh token expires
JWT_REFRESH_EXPIRATION_DAYS=30#Log config
LOG_FOLDER=logs/
LOG_FILE=%DATE%-app-log.log
LOG_LEVEL=error#Redis
REDIS_HOST=redis-host
REDIS_PORT=6379
REDIS_USE_PASSWORD=no
REDIS_PASSWORD=your-password```
## Project Structure
```
src\
|--config\ # Environment variables and configuration related things
|--controllers\ # Route controllers (controller layer)
|--dao\ # Data Access Object for models
|--contract\ # Contracts for all dao
|--implementation # Implementation of the contracts
|--db\ # Migrations and Seed files
|--models\ # Sequelize models (data layer)
|--routes\ # Routes
|--services\ # Business logic (service layer)
|--contract\ # Contracts for all service
|--implementation # Implementation of the contracts and unit test files
|--helper\ # Helper classes and functions
|--validations\ # Request data validation schemas
|--app.js # Express app
|--cronJobs.ts # Job Scheduler
|--index.ts # App entry point
```## License
[MIT](LICENSE)