Course contentsShow
← Web Development
Lesson 1425 of 2,98226. Code Quality ToolsFree lesson

Installing ESLint in Your Project

Setting up ESLint with npm/yarn and understanding package.json dependencies for development.

Installing ESLint in Your Project

You'll learn how to add ESLint to your project using npm or yarn and understand where it fits in your development workflow.

Now that you know what ESLint is and why you'd use it, let's actually get it into your project. Installing ESLint is straightforward, but understanding where it lives and how your package manager tracks it is crucial for team collaboration and consistent development environments.

Installing with npm

In your project directory, run:

npm install eslint --save-dev

Or with yarn:

yarn add eslint --dev

Understanding the --save-dev Flag

The --save-dev (or --dev) flag is important. It tells your package manager: "This is a development dependency." ESLint checks your code while you're writing it—it doesn't need to be shipped with your final application to production.

Think of it like scaffolding on a building site: essential while constructing, but removed before anyone moves in.

What Happens to package.json

After installation, open your package.json file. You'll see ESLint listed under devDependencies:

{
  "devDependencies": {
    "eslint": "^8.0.0"
  }
}

This distinction matters because when someone else clones your project and runs npm install, they get ESLint too. But when deploying to production with npm install --production, development dependencies are skipped, keeping your production bundle lean.

Verifying Installation

Check that ESLint installed correctly:

npx eslint --version

You should see the version number printed out.

Key Takeaway: Installing ESLint as a dev dependency with npm install eslint --save-dev ensures it's tracked in package.json for team consistency while keeping it out of production builds.