Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Node - get the contents of all the files in DIR
const fs = require('fs')
const path = require('path')
const DIR = 'input/';
const readFile = name => fs.readFileSync(name);
(async () => {
const files = fs.readdirSync(DIR)
.filter(s => s.match(/\.csv$/)) // only .csv files -- change to whatever you want.
.map(name => path.join(DIR, name))
.map(readFile)
.map(buffer => buffer.toString());
console.log(files);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.