Home

Awesome

<picture> <source media="(prefers-color-scheme: dark)" srcset="art/screen-dark.jpg"> <source media="(prefers-color-scheme: light)" srcset="art/screen-light.jpg"> <img alt="ts-express-boilerplate logo" src="art/screen-dark.jpg"> </picture>

Typescript Express Boilerplate

CircleCI (all branches)

This boilerplate is a generic "template" for a web application based on following modules:

TypeModule
:bucket: Web FrameworkExpressJS 4
:dna: OrmTypeORM
:roll_of_paper: LoggingWinston
:toolbox: Utilities<ul> <li>Async</li><li>Dotenv</li><li>LOdash</li></ul>
:adhesive_bandage: Testing<ul><li>Jest</li><li>Supertest</li><li>Sinon,JS</li></ul>
:toothbrush: Linting<ul><li>ESlint</li><li>Prettier</li></ul>
:man_artist: Artworkby faudas

:it: Made in Italy :it:

How to start

  1. Clone repository and Install dependencies
$ git clone https://github.com/d4rkstar/ts-express-boilerplate.git my-awesome-project
$ cd my-awesome-project
$ yarn install
  1. Build sources
$ yarn run build
  1. If you need, create a database

  2. Copy .env.example to .env

  3. Edit .env file and put required variables

  4. Migrate database

  5. To run tests

$ yarn run test
  1. To start
$ yarn run start

:point_right: Info

Before start coding, ensure to:

$ ./publish.sh "my-awesome-project" "My Awesome Project API Endpoint test" "Me"

File package.json was updated!
šŸ’„ Removing CircleCI original dir
šŸ’„ Removing Art original dir
šŸ–‹ļø Generating new README.md
šŸ”„ Republish Completed!

If you need to use database and typeorm:

If you don't need to use database and typeorm:

To add new routes and routers, check the App::mountRoutes method.

It's quite simple to add new routes!

Docker

  1. Build image
$ docker build -t ts-express-boilerplate .
  1. Run image :)
$ docker run -d -p 3000:3000 --name ts-express-boilerplate ts-express-boilerplate:latest

Migrations :-)

Create an entity

$ yarn run typeorm entity:create src/entities/User

and modify at your needs. Then generate migration for this Entity:

$ yarn run  typeorm migration:generate -d dist/Datasource.js src/migrations/use

Finally run migrations:

$ yarn run migrate-dev

Info: migrate-dev will build js source before run migrations. If you need to run migrations in prod (!!), you can consider the migrate script. Adjust datasources at your needs.

Coding guidelines

I suggest reading this useful article:

Using ESLint and Prettier in a TypeScript Project

To activate ESlint in Webstorm, follow this link:

ESLint in Webstorm

To use ESlint from command line:

$ eslint --fix --ignore-path .eslintignore src/*.ts

Some useful references:

For testing:

Deploy to openshift