Eslint configuration for Node Project
Tags: javascript, webdev, programming, codenewbie
Published: 2021-10-21 08:13:43

We'll talk about how to enforce a style guide in our Nodejs project today in this brief post. When writing code, it's important to stick to a style and be consistent.
![eslint](https://media.giphy.com/media/l2JejvPDaGGUaeEb6/giphy.gif)

🥦 Let's get started by configuring our integrated environment. To begin, go to the vscode market and look for the eslint extension. This adds ESLint support to Visual Studio Code.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/arzh4ck3gtklxodxnazm.PNG)

---
With that out of the way, make a folder and change directory: `mkdir eslint-tut ` and `cd eslint-tut`

Open your IDE terminal and run this node package execute `npx eslint --init` 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lb6s4ep97hnbhmujbvgr.PNG)
 
To select a guide, simply follow the instructions. My main goal is to have a standard guide.
🥦 Choose to check syntax, find problems and enforce code style.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i5xdd1r1jbejvpo4ksj3.png)
🥦 CommonJS (require/exports).
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ix59zdlx3odqx85acea3.PNG)
🥦 None of these
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gikqzlvcj4e5zs7mek4h.PNG)
🥦 Since I am not using typescript, i choose no.
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uflgfnefuvnulj2pk6n1.PNG)
🥦 I am running a node app,  choose node.
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u471fvcpthetwq2m02wu.PNG)
🥦  I used a popular style guide.
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r0x3iarqgtwyuchx47cr.PNG)
🥦I chose standard over Airbnb and Google. Choose the one that suits your app best.
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p3h9284dpjo9h9798wzz.PNG)
🥦 For my config file format, I went with JavaScript.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bjcbe5zjksj0lki5czc0.PNG)
🥦 Yes, i'd love to install with npm
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e5uhqyolhltib2immite.PNG)
🥦 When installation is complete you should have .eslintrc.js 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gk0dxa135rshef1vxode.PNG)
 🥦 Eslint config settings and rules
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ajs73jqw5a9mmxvv6rlj.PNG)

How to use <mark>eslint</mark> in your project in two different ways.

1) Using a script
2) Using vscode commands

Run `npm init -y` to initiate your project.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4jp1aeziupaef89lryhg.PNG)
 Let's write a script in our package.json file. When we run this script its formats our code. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lh86sb9ushtwjfp49p6j.PNG)

Now run the command beelow: 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zn1l4n3ey078mts3gf5f.PNG)

This should fix all inconsistencies in your code.

## Error Fixing using vsccode command
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xbg9hn9ytr03lcadlalw.PNG)
```Javascript
🥦 To fix errors automaically using vscode: ctrl + shift + p , type in eslint and select Eslint fix all auto-fixable problems 
```

 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l4lhhl43tdb6xvtomqxa.PNG)

Result: 🎯
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v1kg7y6n8w0000t1sy0s.PNG)

## Conclusion
I hope this post is helpful and will aid in writing better code for your next project. Thanks for reading.