This is my batteries included generic TypeScript starter, with:
- 🟩 Node.js 20
- ✏️ TypeScript 5.3
- 📚 ECMAScript Modules
- ⚙️ NPM package manager
- 🚥 testing with Jest
- 📦 bundling with esbuild
- ⚗️ Code linting & formatting with ESLint + Prettier
- 🔬 VS Code configuration for debugging
- 🔥 hot reloading
- 🔁 GitHub Actions workflow to run code quality checks and tests
- Make sure you have Node.js installed. This is built, configured and tested with
Node.js 20
. - Install VS Code, and the following extensions:
How to use this template?
- Make sure prerequisites are met.
- Clone this repository.
- Delete
package-lock.json
. - Replace janik6n in
package.json
with your own username. - Install dependencies by running
npm install
on the project root directory. - Start developing. See below for available scripts.
To run TypeScript to JavaScript transpiling and to run transpiled dist/index.js
in watch mode (a.k.a. hot reloading), run npm run dev
.
To run tests, you have a couple of options:
- run
npm run test
- to include coverage report, run
npm run test:cov
- to run tests in watch mode, run
npm run test:watch
in separate terminal session than your development server.
Lint a.k.a. check the formatting of the source code with npm run lint
.
Basic 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
.
Future plans: build as Docker container with npm run build:container
.
Serve the built app with npm run start
.
- Jest module mocking does not work. Haven't been able to figure out yet what's the issue with this. Most likely related to kulshekhar/ts-jest#4207.
- https://jestjs.io/docs/getting-started#using-typescript
- https://jestjs.io/docs/ecmascript-modules
- https://kulshekhar.github.io/ts-jest/
- https://github.com/jest-community/vscode-jest
- https://sixty-north.com/blog/jest-vscode-env-vars.html
- https://github.com/microsoft/vscode-recipes/tree/main/debugging-jest-tests
- https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
- https://github.com/jest-community/vscode-jest#runmode
MIT License. Copyright janik6n.