https://github.com/alexandervantrijffel/ts-node-project-template
Starter kit for new Node.js Typescript packages
https://github.com/alexandervantrijffel/ts-node-project-template
docker esbuild eslint esm github-actions jest multi-stage-build nodejs prettier renovate template typescript
Last synced: 3 months ago
JSON representation
Starter kit for new Node.js Typescript packages
- Host: GitHub
- URL: https://github.com/alexandervantrijffel/ts-node-project-template
- Owner: alexandervantrijffel
- Created: 2021-08-17T12:20:40.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-09-25T03:57:35.000Z (over 2 years ago)
- Last Synced: 2023-09-25T07:39:44.737Z (over 2 years ago)
- Topics: docker, esbuild, eslint, esm, github-actions, jest, multi-stage-build, nodejs, prettier, renovate, template, typescript
- Language: TypeScript
- Homepage:
- Size: 9.31 MB
- Stars: 12
- Watchers: 2
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Typescript Node project template
This template contains a full project configuration for Typescript and Node 18 based projects.
Features:
- ESM module
- `build` script that builds a single, minified, tree shaked .build/index.mjs bundle file that does not depend on external packages from node_modules. It comes with a Typescript sourcemap and is built with esbuild-kit/tsx
- `start:watch` script for development mode, this auto rebuilds and restarts the app on changes with`tsx watch`
- extensive lint configuration for standardized, consistent code
- Husky configuration for validating commit messages, lint validation and running tests
- tsconfig project configuration for Node 18 projects based on [best practices for Node 18](https://github.com/tsconfig/bases/blob/main/bases/node16.json)
- jest configuration for unit tests, vitest for test execution [vitest features](https://vitest.dev/guide/features.html)
- multi-staged Docker build with minimal Docker image size
- Github Actions workflow for build, test and Docker build
- both npm and yarn are supported
The build performance in **development build mode** increases significantly when using esbuild instead of the Typescript compiler tsc:

## Getting started
### With npm
Run `npm install` and `npm run serve` to run the application in development mode.
Run `npm run test:watch` to run unit tests in watch mode.
### With yarn
Install yarn v1.22.19 or later.
Run `yarn install` and `yarn serve` to run the application in development mode.
Run `yarn test:watch` to run unit tests in watch mode.
## Docker build
Build the Docker image with `docker build . -t ts-node-project-template` and run it with command `docker run ts-node-project-template`.
The resulting Docker image is only 30MB. This achieved by making use of a multi-stage Docker build and using m03geek/alpine-node:pico-14 as the base image for the production build. This doesn't include npm which saves 33MB and node is packed with upx. This leads to a Docker image that is around 88MB smaller compared to the official node:alpine-14 image.
## Github actions
A Github Actions workflow is included that builds the package and runs the tests. When that succeeds a Docker image is built. Because node_modules are cached, both the build-test and build-docker jobs finish within a minute when the package dependencies can be retrieved from the cache.
Modify the workflow file at `.github/workflows/main.yml` for setting up pushing the Docker image to a registry.
## Danger JS
With Danger JS checks are executed on PR's to validate the quality of the PR. The following checks are implemented in dangerfile.ts:
- Do all tests succeed?
- Does the PR title follow the !(conventional commits)[https://www.conventionalcommits.org/en/v1.0.0] standard?
- Does the PR has a decription?
This is reported on the pull request by Danger JS as comments:

To allow Danger JS to add comments to the PR, take the following steps:
- Create a Github Personal Access Token at https://github.com/settings/tokens/new with permission `public_repo`.
- Add a secret to the repository with name `DANGER_TOKEN` and set the Personal Access Token as the value.
To extend dangerfile.ts with additional rules, make sure you add the `danger` package to the project as dev dependency and run danger locally on a pull request with the following command:
```
DANGER_GITHUB_API_TOKEN= yarn danger pr https://github.com///pull/
```
### Renovate
This template contain a starter configuration for !(Renovate)[https://github.com/renovatebot/renovate]. Renovate automates dependency updates by creating pull requests. Install the Renovate app for Github from !(here)[https://github.com/apps/renovate].