How to configure a solid backend NodeJS stack (2) — Linting and code prettifying

Adam Giacomelli
Sep 7, 2018 · 1 min read

This series consists of:

Linter & Prettifier

Every project needs to have a solid linter — I’m partial to:

To configure it, add the command line tool, the plugin import and Airbnb config to the project:

yarn add -D prettier-eslint-cli eslint-plugin-import eslint-config-airbnb-base

Add a format and lint script to package.json:

...
"format": "prettier-eslint \"src/**/*.js\""
"lint": "eslint \"src/**/*.js\""
...

The format script will auto prettify all the js files inside src, the lint script will only report issues.

And an .eslintrc file with the rules:

{
"extends": "airbnb-base",
"rules": {
"quotes": ["error", "single"],
"no-use-before-define": 0,
"no-param-reassign": 0,
"array-callback-return": 0,
"consistent-return": 0,
"no-return-assign": 0
},
"globals": {
"__root": false
}
}

The rules can be tweaked a little bit since some of them are very restrictive and do not make sense in all setups — other than that the airbnb-base is an excellent starting point (see https://www.npmjs.com/package/eslint-config-airbnb for details).

Wrap up

You can find the code mentioned in this article at https://github.com/adamgiacomelli/nodejs-stack-example — branch part-2/linting-and-prettifying

This is the second article in the series. In the next part we will focus on managing database connections.

Adam Giacomelli

Written by

I am an engineer, software architect and the JavaScript tech lead @povioLabs.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade