January 2020
Intermediate to advanced
470 pages
11h 13m
English
Let's go with a Node example, similar to the command-line pipeline we built earlier in this chapter. Here, we'll build the pipeline we need by hand. We need a function to read all the files in a directory. We can do that (this isn't recommended because of the synchronous call, which is normally not good in a server environment) with something like this:
function getDir(path) { const fs = require("fs"); const files = fs.readdirSync(path); return files;}
Filtering the odt files is quite simple. We start with the following function:
const filterByText = (text, arr) => arr.filter(v => v.endsWith(text));
This function takes an array and filters out any elements that do not end with the given text. So, we can now write ...
Read now
Unlock full access