Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/d4rkstar/ts-express-boilerplate
- Owner: d4rkstar
- License: gpl-3.0
- Created: 2019-04-25T15:19:29.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-01-07T11:53:48.000Z (10 months ago)
- Last Synced: 2024-05-29T04:32:48.381Z (5 months ago)
- Topics: boilerplate, eslint, express, expressjs, jest, nodejs, typeorm, typescript
- Language: TypeScript
- Homepage:
- Size: 1.72 MB
- Stars: 27
- Watchers: 2
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-typescript - ts-express-boilerplate - ExpressJS / Typescript template good to start backend projects, with a focus on simplicity and minimal features :P It has logging and testing configured out of the box. Typeorm is used for data access. (Getting Started with (Awesome) TypeScript / Typescript Project Starters)
README
# 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* -