Installing ESLint in Your Project
What you'll learn: How to add ESLint to your project using npm or yarn, understanding where it lives and why that matters.
The Core Idea
ESLint is a tool that checks your JavaScript code for problems, but first you need to install it. You have two main choices: install it locally (just for one project) or globally (available everywhere on your machine). For team projects, local installation is almost always the right choice because it ensures everyone uses the same version.
Installing ESLint Locally
Run this command in your project directory:
npm install eslint --save-dev
or with Yarn:
yarn add eslint --dev
The --save-dev (or --dev) flag tells the package manager: "This is a development tool, not something my app needs to run in production." ESLint gets added to the devDependencies section of your package.json:
{
"devDependencies": {
"eslint": "^8.50.0"
}
}
Local vs Global: Why It Matters
A global install (npm install -g eslint) puts ESLint on your system path, but creates problems:
- Different projects might need different ESLint versions
- Teammates won't automatically get the same version
- Your CI/CD pipeline needs separate setup
A local install keeps ESLint in your project's node_modules, making it part of the project's reproducible environment. Everyone who runs npm install gets the exact same linting setup.
Running Your Local ESLint
After local installation, run it via npx:
npx eslint --init
Or add it to your package.json scripts for easy access.
Key Takeaway: Always install ESLint locally as a devDependency to ensure consistent linting across your team and avoid version conflicts between projects.