This boilerplate is a generic "template" for a web application based on following modules:
| Type | Module |
|---|---|
| 🪣 Web Framework | ExpressJS 4 |
| 🧬 Orm | TypeORM |
| 🧻 Logging | Winston |
| 🧰 Utilities | |
| 🩹 Testing | |
| 🪥 Linting | |
| 👨🎨 Artwork | by faudas |
🇮🇹 Made in Italy 🇮🇹
- Clone repository and Install dependencies
$ git clone https://github.com/d4rkstar/ts-express-boilerplate.git my-awesome-project
$ cd my-awesome-project
$ yarn install- Build sources
$ yarn run build-
If you need, create a database
-
Copy .env.example to .env
-
Edit .env file and put required variables
-
Migrate database
-
To run tests
$ yarn run test- To start
$ yarn run startBefore start coding, ensure to:
- Remove the .git folder
- Start a new repo, doing a
git init .inside the project folder and adding files withgit 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.shscript command:
$ ./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!
- Build image
$ docker build -t ts-express-boilerplate .- Run image :)
$ docker run -d -p 3000:3000 --name ts-express-boilerplate ts-express-boilerplate:latestCreate an entity
$ yarn run typeorm entity:create src/entities/Userand modify at your needs. Then generate migration for this Entity:
$ yarn run typeorm migration:generate -d dist/Datasource.js src/migrations/useFinally run migrations:
$ yarn run migrate-devInfo: 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.
I suggest reading this useful article:
Using ESLint and Prettier in a TypeScript Project
To activate ESlint in Webstorm, follow this link:
To use ESlint from command line:
$ eslint --fix --ignore-path .eslintignore src/*.ts- TypeORM - http://typeorm.io/#/
- TypeScript Deep Dive - https://basarat.gitbooks.io/typescript/content/
- Tutorial on Typescript - https://blog.risingstack.com/building-a-node-js-app-with-typescript-tutorial/
- Cheatsheet - https://www.sitepen.com/blog/typescript-cheat-sheet
- Jest - https://jestjs.io/docs
- Supertest - https://github.com/visionmedia/supertest
- Superagent - http://visionmedia.github.io/superagent/#post-put-requests
- Sinon - https://sinonjs.org/
- Tutorial typescript api - https://tutorialedge.net/typescript/testing-typescript-api-with-jest/
- Automatic build and deploy - http://www.admin-magazine.com/Archive/2018/47/Automatic-build-and-deploy-with-OpenShift-and-GitLab-CI