skip to content
Arthur Brière
Table of Contents

Where it all started

As a JS developer, I have two main issues to write clean code. The first is the callback style, like:

fs.readFile(`path-to-my-file`, (err, data) => {
// Do some stuff with my data
});

Not really scary at first sight, but it can be, if for example the file contains a list of paths that you want to read after. It becomes:

// -- my-files-list.txt --
// file-1.txt
// file-2.txt
// file-3.txt
fs.readFile('my-files-list.txt, (err, data) => {
// Get the files
// files = ["file-1.txt", "files-2.txt", "file-3.txt"];
const files = data.toString().split(/\r?\n/);
files.forEach((file) => {
fs.readFile(file, (err, data) => {
// Do some stuff with sub files
})
})
}
A covered up pug in the woods

Introducing Piwa