Skip to content

Instantly share code, notes, and snippets.

@VictorCandido
Created March 1, 2024 15:46
Show Gist options
  • Select an option

  • Save VictorCandido/9718c39fcf3ca38dfa55b4448e83c7cd to your computer and use it in GitHub Desktop.

Select an option

Save VictorCandido/9718c39fcf3ca38dfa55b4448e83c7cd to your computer and use it in GitHub Desktop.
NodeJs Typescript Vitest Setup

NodeJs Typescript Vitest Setup

Init project

Run commands above to setup project

  • npm init -y to init NodeJs project
  • npm install typescript tsx @types/node vitest -D to install typescript and Vitest as testing library
  • npx tsc --init to create typescript configuration file

Typescript setup

Edit below items in tsconfig.json

  • "target": "ES2020"
  • "rootDir": "./src"
  • "outDir": "./dist"
  • "paths": { "@/*": ["./src/*"] }

NodeJs Scripts

Create the following scripts on package.json

  "scripts": {
    "dev": "tsx watch src/index.ts",
    "start": "node build/index.js",
    "build": "tsc",
    "test": "vitest"
  },

Now create src/index.ts file and start coding :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment