These are some quick notes on creating a new Typescript Node.js project that uses live development reloading with ts-node-dev and testing with Jest.

Setup Typescript

# Setup yarn package w/ default options
yarn init -y

# Add typescript deps
yarn add typescript ts-node-dev @types/node --dev


Add a tsconfig.json to configure the Typescript compiler. You can use yarn tsc --init to create a file with a list of all options. A simplified version that compiles all code in /src and outputs it to /build:

  "compilerOptions": {
    "esModuleInterop": false,
    "module": "commonjs",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "outDir": "build",
    "strict": true,
    "target": "es6"
  "include": ["src/**/*"]

package.json scripts

Add a scripts section to package.json for development and building. Replace index.ts with the entry point:

"scripts": {
  "dev": "ts-node-dev --respawn  ./src/index.ts",
  "prod": "tsc --build && node ./build/index.js",
  "build": "tsc"

You can now start development mode using:

yarn run dev

Setup Jest for testing

# Install deps
yarn add jest @types/jest ts-jest --dev

# Create a default config file
yarn ts-jest config:init

Add new scripts to package.json to run tests in watch mode or in debug mode.

"scripts": {
    "test" : "jest --watchAll",
    "test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand"

Create a sample test in src. By default jest will look for files ending in .spec.ts or .test.ts, though this can be customized.

An example test:

import { doSomething } from "./index";

test('sample', () => {

Debugging with Chrome

To run tests with a debugger, add debugger to your test case you wish to debug. Run yarn test:debug. Open about:inspect in Chrome and select Open dedicated DevTools for Node. The dev tools instance should connect. Note: this can be flaky with WSL2. You might need to run wsl --shutdown in Powershell in order to allow node to run the debugger on the proper port. See bug.

Debugging with VSCode

Create a launch.json file in a .vscode\ subfolder of your projects roots. You'll now be able to launch a debugger directly in VSCode via Run > Start Debugging.

  "version": "0.2.0",
  "configurations": [
      "name": "Debug Jest Tests",
      "type": "node",
      "request": "launch",
      "runtimeArgs": [
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "port": 9229

Setup prettier

I use the Prettier VSCode extension for code formatting. Generally I don't like to think about formatting and have the VSCode set to auto-format on save:

// Inside vscode settings
"editor.formatOnSave": true,

To avoid auto-formatting causing problems when I'm working outside of my projects, I also require a .prettierrc file to be present in the project for formatting to work.

"prettier.requireConfig": true

An example .prettierrc file:

  "arrowParens": "avoid",
  "semi": true,
  "singleQuote": true,
  "printWidth": 80,
  "bracketSpacing": false