Skip to content
LeChatErrant edited this page Mar 20, 2021 · 13 revisions

About

Linter

Code styling is handled by eslint

We're using the AirBnb configuration extended for typescript. It will ensure coherence across the whole codebase, and make sure you're following general good practices

Use npm run lint to check coding style and automatically fix errors

Linter

Logging

The application comes with a custom logger made with winston.

It allows you to output nicely formated logs as simply as

logger.info('Server listening on 8000')

Error logs are written into logs/error.log, and a mix of all logs level from info are written into logs/all.log

In production mode, logs are not written in stdout, only in files

This is essential as console.log is a blocking operation

It reduces the IO usage too

Additionally, all requests are automatically logged too, thanks to morgan

Logs

Handlers

Express doesn't handle errors thrown in an async context.

It means that even with an error middleware, errors won't be catched if they are thrown from an async handler, and your app will crash

I know

It's insane

To avoid this problem, handlers need to be wrapped in express-async-handler

router.post('/signin', handler(async (req, res) => {
  /*  Errors can safely be thrown */
}));
Clone this wiki locally