NodeJS Express Setup with Typescript, ESLint, Prettier

After extensive research and hands-on work, I’ve refined the best approach to set up a new Node.js project with Express, TypeScript, ESLint, and Prettier. Follow these steps to quickly get started and have your project ready for development.

– Project…


This content originally appeared on DEV Community and was authored by Vishal Jagamani

After extensive research and hands-on work, I've refined the best approach to set up a new Node.js project with Express, TypeScript, ESLint, and Prettier. Follow these steps to quickly get started and have your project ready for development.

- Project Initialization: create a new Node.js project:

npm init -y

- Install Dependencies: Install required packages:

npm install express cors dotenv
npm install --save-dev typescript @types/node @types/express @types/cors ts-node

- Configure TypeScript: create a tsconfig.json file:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "node",
    "outDir": "./dist",
    "rootDir": "./src",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "sourceMap": true
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules"]
}

- Update package.json scripts: Modify package.json to include:

{
  "type": "module",
  "scripts": {
    "start": "node dist/app.js",
    "build": "tsc",
    "dev": "ts-node-esm src/app.ts",
    "test": "echo \"Error: no test specified\" && exit 1"
  }
}

- Install ESLint & Prettier:

npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
npm install --save-dev prettier eslint-config-prettier eslint-plugin-prettier

- Create eslint.config.mjs (updated ESLint configuration):

import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import prettier from 'eslint-plugin-prettier';
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
    baseDirectory: __dirname,
    recommendedConfig: js.configs.recommended,
    allConfig: js.configs.all,
});

export default [
    ...compat.extends('eslint:recommended', 'plugin:@typescript-eslint/recommended'),
    {
        plugins: {
            '@typescript-eslint': typescriptEslint,
            prettier,
        },
        languageOptions: {
            globals: {
                ...globals.node,
            },
            parser: tsParser,
            ecmaVersion: 'latest',
            sourceType: 'module',
        },
        rules: {
            semi: 'off',
            quotes: ['error', 'single', { allowTemplateLiterals: true }],
            '@typescript-eslint/no-explicit-any': 'off',
        },
    },
];

- Configure Prettier:

  • Create .prettierrc file:
{
  "tabWidth": 4,
  "singleQuote": true,
  "trailingComma": "all",
  "semi": true,
  "printWidth": 150,
  "pluginSearchDirs": false
}
  • Create .pretterignore file:
**/.git
**/.svn
**/.hg
**/node_modules

- Recommended folder structure:

/src
   /config       → Configuration files  
   /routes       → Micro routes  
   /controllers  → Controller functions for handling requests  
   /services     → Service files for business logic  
   /types        → TypeScript interfaces and type definitions  
   /utils        → Utility functions  
.env  
.eslintrc.json  
.prettierignore  
.prettierrc  
package-lock.json  
package.json  
tsconfig.json  

- Additional useful packages

  • Helmet - Security middleware
npm install helmet
  • Passport - Authentication middleware
npm install passport
  • Winston - Logging
npm install winston

This structured guide ensures an efficient setup for a clean, maintainable Node.js project. 🚀


This content originally appeared on DEV Community and was authored by Vishal Jagamani


Print Share Comment Cite Upload Translate Updates
APA

Vishal Jagamani | Sciencx (2025-02-05T17:39:33+00:00) NodeJS Express Setup with Typescript, ESLint, Prettier. Retrieved from https://www.scien.cx/2025/02/05/nodejs-express-setup-with-typescript-eslint-prettier/

MLA
" » NodeJS Express Setup with Typescript, ESLint, Prettier." Vishal Jagamani | Sciencx - Wednesday February 5, 2025, https://www.scien.cx/2025/02/05/nodejs-express-setup-with-typescript-eslint-prettier/
HARVARD
Vishal Jagamani | Sciencx Wednesday February 5, 2025 » NodeJS Express Setup with Typescript, ESLint, Prettier., viewed ,<https://www.scien.cx/2025/02/05/nodejs-express-setup-with-typescript-eslint-prettier/>
VANCOUVER
Vishal Jagamani | Sciencx - » NodeJS Express Setup with Typescript, ESLint, Prettier. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/02/05/nodejs-express-setup-with-typescript-eslint-prettier/
CHICAGO
" » NodeJS Express Setup with Typescript, ESLint, Prettier." Vishal Jagamani | Sciencx - Accessed . https://www.scien.cx/2025/02/05/nodejs-express-setup-with-typescript-eslint-prettier/
IEEE
" » NodeJS Express Setup with Typescript, ESLint, Prettier." Vishal Jagamani | Sciencx [Online]. Available: https://www.scien.cx/2025/02/05/nodejs-express-setup-with-typescript-eslint-prettier/. [Accessed: ]
rf:citation
» NodeJS Express Setup with Typescript, ESLint, Prettier | Vishal Jagamani | Sciencx | https://www.scien.cx/2025/02/05/nodejs-express-setup-with-typescript-eslint-prettier/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.