Skip to content

Instantly share code, notes, and snippets.

@keshav-c
Last active March 23, 2025 06:21
Show Gist options
  • Save keshav-c/063f5394f8940071dd8403fe161dbfab to your computer and use it in GitHub Desktop.
Save keshav-c/063f5394f8940071dd8403fe161dbfab to your computer and use it in GitHub Desktop.
Node (TypeScript) project setup with yarn on VS Code

Nodejs (TS) setup

startup

mkdir my-project
cd my-project
yarn init -2
yarn set version stable
yarn install
yarn add -D eslint @eslint/js typescript typescript-eslint @types/node tsx prettier

Update package.json

Add the following properties to it. Check the version of nodejs you are using first

{
  "engines": {
    "node": "22.14.0"
  },
  "scripts": {
    "build": "tsc -p .",
    "watch": "tsx watch --include 'src/**/*.ts' src/index.ts",
    "lint": "eslint ."
  },
  "type": "module"
}

Add a basic ./tsconfig.json

{
  "compilerOptions": {
    "strict": true,
    "declaration": true,
    "module": "NodeNext",
    "moduleResolution": "nodenext",
    "sourceMap": true,
    "noImplicitAny": true,
    "removeComments": true,
    "useUnknownInCatchVariables": false,
    "noEmitOnError": true,
    "baseUrl": "./src",
    "outDir": "./dist",
    "target": "ES2022"
  },
  "include": ["src/**/*"]
}

Add ./.prettierrc

{
  "singleQuote": true,
  "tabWidth": 2,
  "printWidth": 100
}

Add ./eslint.config.mjs

// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
  { ignores: ['node_modules/**', '.yarn/**', '.pnp.*', 'dist/**'] },
  eslint.configs.recommended,
  tseslint.configs.recommended,
  {
    languageOptions: {
      globals: {
        console: 'readonly',
        process: 'readonly',
      },
      parserOptions: {
        ecmaVersion: 'latest',
      },
    },
    files: ['src/**'],
    rules: {
      '@typescript-eslint/no-explicit-any': 'off',
      'no-unused-vars': 'off',
      '@typescript-eslint/no-unused-vars': [
        'error',
        {
          args: 'all',
          argsIgnorePattern: '^_',
          caughtErrors: 'all',
          caughtErrorsIgnorePattern: '^_',
          destructuredArrayIgnorePattern: '^_',
          varsIgnorePattern: '^_',
          ignoreRestSiblings: true,
        },
      ],
    },
  },
);

Extra Steps

VSCode requires special configuration for TypeScript to work when using Plug'n'Play installs. Open the project in VS Code

  • ZipFS (arcanis.vscode-zipfs) VS Code extension is needed
  • run yarn dlx @yarnpkg/sdks vscode which creates a .vscode folder
  • VSCode requires you to explicitly activate the custom TS settings
    • Press ctrl+shift+p in a TypeScript file
    • Choose "Select TypeScript Version"
    • Pick "Use Workspace Version"

Other recommended extensions for VS Code

  • ESLint (dbaeumer.vscode-eslint)
  • Prettier (esbenp.prettier-vscode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment