This is my batteries included TypeScript starter updated for 2025, with:
- π© Node.js 22
- βοΈ TypeScript 5.7
- π ECMAScript Modules
- βοΈ NPM package manager
- βοΈ code linting & formatting with ESLint & Prettier
- π₯ testing with Vitest
- π¬ VS Code configuration for debugging and testing
- π₯ hot reloading
- π¦ production bundling with esbuild
- π³ optional production ready Docker image creation
- π GitHub Actions workflow to run code quality checks and tests
This starter is more geared towards backend than frontend use.
- Make sure you have Node.js 22 installed. This is built, configured and tested with
Node.js 22
. - If you want to use VS Code, make sure the following extensions are installed:
How to use this template?
- Make sure prerequisites are met.
- Download the repository as zip so you don't have to deal with git history of this repository.
- Delete
package-lock.json
. - Replace
janik6n
inpackage.json
with your own username, along with other info. - Install dependencies by running
npm install
on the project root directory. - Start developing. See below for available scripts.
Following scripts have been configured, and they should give ideas for further development.
To run TypeScript to JavaScript transpiling and to run transpiled ./dist/index.mjs
run npm run dev
. Watch mode (a.k.a. hot reloading) is available with npm run dev:watch
. Development serving is handled with tsx.
Test are run with Vitest, and different test scenarios are handled with Vitest workspaces.
To run tests, you have a several of options:
- Run all tests with
npm run test
. - Include coverage report with
npm run test:cov
. - Run unit tests with
npm run test:unit
. This runs all tests which are in files with name*.unit.test.ts
. - Run integration tests with
npm run test:integration
. This runs all tests which are in files with name*.integration.test.ts
. - Run end-to-end (e2e) tests with
npm run test:e2e
. This runs all tests which are in files with name*.e2e.test.ts
. - Run unit and integration tests in watch mode with
npm run test:watch
in separate terminal session than your development server. - Run unit and integration tests in CI environment with
npm run test:ci
. Note: this script exists so it's easy to configure which tests are run in CI.
Format the source code with Prettier by running npm run format
.
Lint a.k.a. check the formatting of the source code with npm run lint
.
The idea is to run ESLint & Prettier on VS Code as you code, so this script is mostly for code quality checks in CI. Prettier is run as ESLint plugin.
Build the production bundle with esbuild by running npm run build
. Build is configured in build.js
.
Build command explained: "build": "rimraf ./dist && npx tsc --noEmit && node build.js"
:
rimraf ./dist
: delete ./dist foldernpx tsc --noEmit
: run type checksnode build.js
: build and bundle with esbuild, which does not do type checking, but it creates nice small bundles
Sometimes it's necessary to see the built app with just transpiling without bundling. This can be accomplished with npm run build:tsc
.
Run the built app with npm run start
.
Run npm run check:container
to check Docker build for issues, without actually building the image. Dockerfile
is configured so that failing checks will exit with error status. See Build checks | Docker Docs for more info.
Run npm run build:container
to build the app as Docker container. Multi-stage build is used to minimize the production image size. Debian-based image is used to minimize the risk of compatibility issues.
Run the containerized app with npm run start:container
.
There are two debugger launch configurations included:
Debug Current File
is meant to debug the currently active TypeScript file.Debug Current Test File
is same, but for test files.
None as of now. π¦
Here are some things that could be included in a starter, but are not in this one:
- Monorepo setup
- Any particular appβs source code
- Git pre-commit hooks
- https://eslint.org/
- https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
- https://prettier.io/
- https://github.com/prettier/eslint-plugin-prettier
- https://typescript-eslint.io/
- https://code.visualstudio.com/docs/typescript/typescript-debugging
- https://code.visualstudio.com/docs/editor/testing
- https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
- https://marketplace.visualstudio.com/items?itemName=vitest.explorer
- https://vitest.dev/guide/debugging
- https://hub.docker.com/_/node
- https://snyk.io/blog/choosing-the-best-node-js-docker-image/
- https://docs.docker.com/build/checks/
MIT License. Copyright janik6n.