Sami
Sami

Reputation: 1491

Read JSON file in a directory and its sub-directories

I have a file named file.json in the /assets directory and some of its subdirectories as well. Is there a way that I can search the assets directory and read each of the file.json file using the fs.readFileSync method at once?

Upvotes: 0

Views: 277

Answers (1)

Meir
Meir

Reputation: 14395

Not sure if you can do it synch, yet, you can use glob and stream-concat-files. Note the the concat by default is to a file but you can stream it to a a string buffer writeable stream.

glob('asset/**/file.json', function(err, files){concatFiles(files, 'concat.json', function(err){})});

Upvotes: 1

Related Questions