π Context
Before moving to MongoDB, this lecture covers setting up ESLint together with Prettier to improve code quality. This is optional if not using VS Code or if another linter is already part of the workflow β otherwise, it's a worthwhile step.
π‘ What ESLint does
π Constantly scans code to find potential errors or bad coding practices.
βοΈ It's highly configurable to match personal coding habits and standards.
π€ How ESLint and Prettier Work Together
π¨ Prettier remains the main code formatter (already set up in an earlier section).
π¨ ESLint will be configured to only highlight errors/bad practices, based on a defined set of rules β not to handle formatting itself.
πΉ Step 1: Install the ESLint Extension in VS Code
π§© Go to the Extensions panel.
π Search for ESLint and install it.
π Reload the window if prompted.
β Confirm the Prettier extension is also installed
πΉ Step 2: Install ESLint-Related Dev Dependencies
Install all required packages with one command:
npm install eslint prettier eslint-config-prettier eslint-plugin-prettier eslint-config-airbnb eslint-plugin-node eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react --save-devπ¦ What each package does
π¦ Package | π― Purpose |
|---|---|
| π οΈ The core linter |
| π¨ The code formatter |
| π« Disables ESLint's own formatting rules, since Prettier handles formatting |
| β οΈ Lets ESLint show Prettier formatting issues as actual lint errors while typing |
| π A popular, widely-used JavaScript style guide to base the rules on |
| π’ Adds rules specific to catching common Node.js mistakes |
| π Required dependencies of the Airbnb style guide, even though this isn't a React project |
π‘ Important Notes
π§ͺ
-save-devβ these are all dev dependencies, since they're only needed during development, not in production.π All packages must be installed locally to the project β installing them globally would not work correctly.
π³ This entire setup is described as a "recipe" to follow rather than something requiring deep understanding β the same
package.jsondependency list can simply be copied into future projects and reinstalled.

πΉ Step 3: Configuration Files
Two configuration files are needed β both already provided as starter files in this project.
π .prettierrc
Defines Prettier's formatting preferences (e.g. always using single quotes).
π .eslintrc.json
{
"extends": ["airbnb", "prettier", "plugin:node/recommended"]
}
π‘ How this works
π Uses the Airbnb JavaScript style guide.
π¨ Enables Prettier compatibility.
π’ Adds the Node.js recommended ESLint rules.
πΉ Step 4: Customizing Individual ESLint Rules
ESLint enforces many rules by default, but each can be individually turned off, set to warn, or left as an error.
π Examples of Customized Rules
β οΈ
no-consoleβ set towarnsoconsole.log()is allowed during development.π«
consistent-returnβ disabled since functions like Express middleware don't always return a value.β
no-unused-varsβ kept as an error, with exceptions for common Express parameters (req,res,next, etc.).

π Where to Explore More Rules
π The official ESLint documentation lists every configurable rule.
π‘ Rather than reading everything upfront, it's usually easier to adjust rules as they come up during development.
πΉ Step 5: Seeing ESLint in Action
A few intentional issues are introduced into server.js to demonstrate live linting.
π§ͺ Example 1 β Missing Blank Line
π Missing a blank line after the
requirestatements.π¨ ESLint flags it until the blank line is added.

π§ͺ Example 2 β Reassigning a const
const x = 23;
x = 66;
β ESLint reports an error because constants cannot be reassigned.
Now remove this:
const x = 23;
x = 66;πΉ Step 6: Reusing This Setup in Future Projects
To use the same setup again:
π Copy the ESLint-related dependencies from
package.json.π¦ Run the install command with
-save-dev.
π Installing a Specific Version
npm install eslint@5.16.0β Key Takeaways
π οΈ ESLint finds code issues, while π¨ Prettier handles formatting.
π Airbnb provides a popular base ESLint configuration.
βοΈ ESLint rules can be configured as
off,warn, orerror.π¨
no-unused-varscatches unused variables, with exceptions for Express parameters likereq,res, andnext.π This ESLint/Prettier setup can be reused across future Node.js projects.
β‘οΈ Note
You can also see all the eslint related issues in the problems tab

π Moving on to MongoDB β one of the biggest and most important sections of the course.