项目作者: d4rkstar

项目描述 :
Typescript Express Boilerplate
高级语言: TypeScript
项目地址: git://github.com/d4rkstar/ts-express-boilerplate.git
创建时间: 2019-04-25T15:19:29Z
项目社区:https://github.com/d4rkstar/ts-express-boilerplate

开源协议:

下载





ts-express-boilerplate logo

Typescript Express Boilerplate

CircleCI (all branches)

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

Type Module
:bucket: Web Framework ExpressJS 4
:dna: Orm TypeORM
:roll_of_paper: Logging Winston
:toolbox: Utilities
:adhesive_bandage: Testing
:toothbrush: Linting
:man_artist: Artwork by faudas

:it: Made in Italy :it:

How to start

  1. Clone repository and Install dependencies
  1. $ git clone https://github.com/d4rkstar/ts-express-boilerplate.git my-awesome-project
  2. $ cd my-awesome-project
  3. $ yarn install
  1. Build sources
  1. $ 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

  1. $ yarn run test
  1. To start
  1. $ 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 <url>
  • Adjust the package.json author and remote git repo. Now you can use the publish.sh script command:
  1. $ ./publish.sh "my-awesome-project" "My Awesome Project API Endpoint test" "Me"
  2. File package.json was updated!
  3. 💥 Removing CircleCI original dir
  4. 💥 Removing Art original dir
  5. 🖋️ Generating new README.md
  6. 🔥 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
  1. $ docker build -t ts-express-boilerplate .
  1. Run image :)
  1. $ docker run -d -p 3000:3000 --name ts-express-boilerplate ts-express-boilerplate:latest

Migrations :-)

Create an entity

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

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

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

Finally run migrations:

  1. $ 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:

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

Some useful references:

For testing:

Deploy to openshift