Skip to content

REST API boilerplate with Typescript, Express.js, Typeorm and Mocha.

License

Notifications You must be signed in to change notification settings

Rossella-Mascia-Neosyn/typeplate

 
 

Repository files navigation

Typescript / Express / Typeorm REST API boilerplate

Node TypeScript Express Typeorm Mocha

Build Coverage Status CodeFactor Grade Requires.io (branch) Snyk Vulnerabilities for GitHub Repo

MIT Licence

Ready to use RESTful API boilerplate builded with Express.js, Typescript TypeORM and Mocha. 🤘

Thanks to Daniel F. Sousa for inspiration with her Express ES2017 REST API boilerplate 🍺 🍺 🍺

> Features

  • Basics
    • Clear & clean code architecture with classic layers such controllers, services, repositories, models, ...
    • Object Relational Mapping with typeorm.
    • Entity generation with rsgen.
    • Business validation with self designed business members.
    • Logs management with morgan and winston.
    • Changelog completion with auto-changelog.
    • Testing with included unit and e2e test sets builded with mocha, chai, sinon and supertest.
    • Documentation with api-doc.
  • Security
  • Authentication
  • Performances
  • Assets management
    • Customizable file upload with multer.
    • Customizable image resizing with jimp.

> Table of contents

> Getting started

Prerequisites

  • Git
  • Node.js >= 14.16.0
  • NPM >= 6.14.0
  • A database engine with a dedicated database

When you're with that, starting your project is a matter of minutes. 🕛

Step 1: install

$ git clone https://github.com/konfer-be/typeplate.git path-to/your-project-name/

Step 2: go to

$ cd path-to/your-project-name/

Step 3: build

$ npm run kickstart:dev

Step 4: setup package.json

Open the ./package.json file and edit it with your own values.

Step 5: setup environment

Open ./dist/env/development.env and fill the required env variables (uncommented in the file). See env variables list for more informations.

# Access token Secret passphrase
ACCESS_TOKEN_SECRET = "your-secret"

# CORS authorized domains
AUTHORIZED = "http://localhost:4200"

# API domain
DOMAIN = "localhost"

# Application port.
PORT = 8101

# Refresh token Secret passphrase
REFRESH_TOKEN_SECRET = "your-secret"

# Database engine
TYPEORM_TYPE = "mysql"

# Database server host
TYPEORM_HOST = "localhost"

# Database name. Keep it different from your developement database.
TYPEORM_DB = "your-database"

# Database user
TYPEORM_USER = "root"

# Database password
TYPEORM_PWD = ""

# Database port
TYPEORM_PORT = "3306"

Step 6: setup cliamrc.json

Transactional emails are send with cliam behind the scene. Open the .cliamrc.json and fill the required configuration according your sending mode. See Cliam official documentation for more information.

Sandbox is set to true by default and emails are not send. Pass this value to false when you're ready.

Step 7: run

$ nodemon

> Entity generation

Some repetitive tasks such as creating resources can be done easily with rsgen.

See entity generation wiki section to learn more about generated elements and how to use.

> Documentation

$ npm run doc

Generate API documentation website into ./docs/apidoc/.

See apidoc for more informations about customization.

> Tests

$ npm run test --env test

HTML coverage report is generated by Istanbul in ./reports/nyc-coverage.

Bonus with ./insomnia.workspace.json if you wish run manual e2e tests without create the config.

> Continuous integration

Basic Travis-CI configuration is provided in ./.travis.yml file.

> Deployment

Project implements a basic PM2 configuration to allow deployment.

Install PM2 globaly :

$ npm i pm2 -g

Configuration

Configure the ./ecosystem.config.js file with your env informations.

{
  deploy : {
    staging : {
        user : 'node',
        host : '212.83.163.1',
        ref  : 'origin/master',
        repo : 'git@github.com:repo.git',
        ssh_options: ['StrictHostKeyChecking=no', 'PasswordAuthentication=yes', 'ForwardAgent=yes'],
        path : '/var/www/staging',
          'post-setup' : 'npm run kickstart:staging && pm2 reload ecosystem.config.js --env staging',
          'post-deploy' : 'npm i && tsc && pm2 reload ecosystem.config.js --env staging'
      }
  }
}

More info about PM2 ecosystem.config.js file.

Deploy

Pm 2 must be installed on the target server and your SSH public key granted.

# Setup deployment at remote location
$ pm2 deploy production setup

# Update remote version
$ pm2 deploy production update

More info about PM2 and PM2 deploy.

> License

MIT

About

REST API boilerplate with Typescript, Express.js, Typeorm and Mocha.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 67.4%
  • JavaScript 32.6%