Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/d4rkstar/ts-express-boilerplate

Typescript Express Boilerplate
https://github.com/d4rkstar/ts-express-boilerplate

boilerplate eslint express expressjs jest nodejs typeorm typescript

Last synced: 3 months ago
JSON representation

Typescript Express Boilerplate

Awesome Lists containing this project

README

        



ts-express-boilerplate logo

# Typescript Express Boilerplate

![CircleCI (all branches)](https://img.shields.io/circleci/project/github/d4rkstar/ts-express-boilerplate.svg)

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

| Type | Module |
|:---------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| :bucket: Web Framework | [ExpressJS 4](https://expressjs.com/) |
| :dna: Orm | [TypeORM](https://typeorm.io/) |
| :roll_of_paper: Logging | [Winston](https://github.com/winstonjs/winston) |
| :toolbox: Utilities |

  • [Async](https://caolan.github.io/async/v3/)

  • [Dotenv](https://github.com/motdotla/dotenv)

  • [LOdash](https://lodash.com/docs/4.17.15)

|
| :adhesive_bandage: Testing |

  • [Jest](https://jestjs.io/)

  • [Supertest](https://github.com/visionmedia/supertest)

  • [Sinon,JS](https://sinonjs.org/)

|
| :toothbrush: Linting |

  • [ESlint](https://eslint.org/)

  • [Prettier](https://prettier.io/)

|
| :man_artist: Artwork | by [faudas](https://www.linkedin.com/in/fausto-d-asero-20953835) |

:it: Made in Italy :it:

## How to start
1. Clone repository and Install dependencies

```bash
$ git clone https://github.com/d4rkstar/ts-express-boilerplate.git my-awesome-project
$ cd my-awesome-project
$ yarn install
```

2. Build sources

```bash
$ yarn run build
```

3. If you need, create a database

4. Copy .env.example to .env

5. Edit .env file and put required variables

6. Migrate database

7. To run tests

```bash
$ yarn run test
```

8. To start

```bash
$ yarn run start
```

## :point_right: Info
Before start coding, ensure to:
- Remove the .git folder
- Start a new repo, doing a ``git init .`` inside the project folder and adding files with ``git add .``
- Add a remote url to your git: ``git remote set-url origin ``
- Adjust the package.json author and remote git repo. Now you can use the ``publish.sh`` script command:

```bash
$ ./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!
```
- Copy .env.example to .env and adjust variables at your needs

If you need to use database and typeorm:
- Set USE_TYPEORM to the value of 1 in .env
- Add a database if you need it and configure datasources (under then datasources folder)

If you don't need to use database and typeorm:
- Set USE_TYPEORM to the value of 0 in .env

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

It's quite simple to add new routes!

## Docker

1. Build image

```bash
$ docker build -t ts-express-boilerplate .
```

2. Run image :)

```bash
$ docker run -d -p 3000:3000 --name ts-express-boilerplate ts-express-boilerplate:latest
```

## Migrations :-)

Create an entity
```bash
$ yarn run typeorm entity:create src/entities/User
```

and modify at your needs. Then generate migration for this Entity:
```bash
$ yarn run typeorm migration:generate -d dist/Datasource.js src/migrations/use
```

Finally run migrations:

```bash
$ 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](https://dev.to/robertcoopercode/using-eslint-and-prettier-in-a-typescript-project-53jb)

To activate ESlint in Webstorm, follow this link:

[ESLint in Webstorm](https://www.jetbrains.com/help/webstorm/eslint.html)

To use ESlint from command line:

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

### Some useful references:

- *TypeORM* -
- *TypeScript Deep Dive* -
- *Tutorial on Typescript* -
- *Cheatsheet* -

### For testing:

- *Jest* -
- *Supertest* -
- *Superagent* -
- *Sinon* -
- *Tutorial typescript api* -

### Deploy to openshift
- *Automatic build and deploy* -