JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11
  • Score
    100M100P100Q68312F
  • License MIT

Zero-config ESLint, Prettier, and Husky setup for Node.js TypeScript backend projects

Package Exports

  • eslint-config-node-ts-backend
  • eslint-config-node-ts-backend/legacy
  • eslint-config-node-ts-backend/prettier

Readme

ESLint Config for Node.js TypeScript Backends

CI/CD Status npm version license

An enterprise-grade, zero-configuration ESLint setup for Node.js TypeScript projects.
Enforce modern best practices, security, and code quality with ease.


Why This Config?

In the world of backend development with Node.js and TypeScript, maintaining high code quality, security, and consistency across a project or an entire organization can be challenging. While tools like ESLint are powerful, configuring them to meet enterprise standards can be a tedious and time-consuming process. This project was born out of the need for a truly zero-configuration setup that embodies the best practices of the industry, inspired by the success of standards like the Airbnb JavaScript style guide.

This isn't just another ESLint config. It's an opinionated, comprehensive, and battle-tested solution that provides:

  • Enterprise-Grade Rules: A curated set of rules from typescript-eslint, eslint-plugin-security, eslint-plugin-sonarjs, and eslint-plugin-unicorn to enforce modern, secure, and maintainable code.
  • Zero Configuration: Simply install and extend. The config intelligently detects your project's features (like TypeScript) and applies the appropriate rules.
  • Prettier Integration: Comes with a strict and opinionated Prettier config to ensure consistent code formatting.
  • Husky & Pre-Commit Hooks: Enforce code quality before code gets committed, with seamless integration with Husky.
  • Future-Proof: Built on ESLint's new flat config system, while maintaining backward compatibility.

Our goal is to make this the de-facto standard for Node.js TypeScript backend projects, just as the Airbnb style guide became for JavaScript.

Features

  • Zero-Config: Works out of the box with sensible, enterprise-grade defaults.
  • TypeScript First: Deep integration with TypeScript, including type-aware linting.
  • Security Focused: Catches common security vulnerabilities before they hit production.
  • Code Quality: Enforces best practices and identifies code smells with SonarJS and Unicorn plugins.
  • Prettier Included: A strict, opinionated Prettier config for consistent formatting.
  • Husky Ready: Simple instructions to set up pre-commit hooks.
  • Monorepo Support: Designed to work seamlessly in monorepo environments.

Installation

  1. Install the config and its peer dependencies:

    npm install --save-dev eslint-config-node-ts-backend eslint prettier typescript
  2. Create your eslint.config.js:

    Create an eslint.config.js file in the root of your project and add the following:

    // eslint.config.js
    import createNodeBackendConfig from 'eslint-config-node-ts-backend';
    
    export default createNodeBackendConfig();

    That's it! The config will automatically detect your project's features and apply the best rules.

Usage

Add Scripts to package.json

Add the following scripts to your package.json to easily run the linter and formatter:

{
  "scripts": {
    "lint": "eslint .",
    "lint:fix": "eslint . --fix",
    "format": "prettier --write .",
    "format:check": "prettier --check ."
  }
}

Prettier Configuration

This package includes a strict and opinionated Prettier configuration. To use it, create a prettier.config.js file in your project root:

// prettier.config.js
import prettierConfig from 'eslint-config-node-ts-backend/prettier';

export default prettierConfig;

To ensure code quality is maintained automatically, we strongly recommend setting up pre-commit hooks with Husky and lint-staged.

  1. Install Husky and lint-staged:

    npm install --save-dev husky lint-staged
  2. Enable Git hooks:

    npx husky install
  3. Add a pre-commit hook:

    npx husky add .husky/pre-commit "npx lint-staged"
  4. Configure lint-staged:

    Add the following to your package.json:

    {
      "lint-staged": {
        "*.{ts,tsx,js,jsx,cjs,mjs}": [
          "eslint --fix",
          "prettier --write"
        ],
        "*.{json,md,yml,yaml}": [
          "prettier --write"
        ]
      }
    }

Now, every time you commit, your code will be automatically linted and formatted!

Customization

While this config is designed to be zero-config, you can easily override or extend it. The createNodeBackendConfig function accepts an options object to customize the configuration.

Example: Overriding a rule

// eslint.config.js
import createNodeBackendConfig from 'eslint-config-node-ts-backend';

export default createNodeBackendConfig({
  rules: {
    'no-console': 'off', // Allow console logs
    'unicorn/prevent-abbreviations': ['error', { 'replacements': { 'req': false } }]
  }
});

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.