I am trying to read all json file using loop, in my application. Here is code to read a single file, which is working perfectly fine.
const translations = require("../data/hello" + fileEndWith);
But there is 10+ files in directory translations, so I don't want to write same code for each files, instead of I want to read in loops.
let fs = require('fs');
let fileEndWith = "en.json";
fs.readdir("../data/", (err, fileNames) => {
fileNames.forEach((fileName) => {
if(fileName.indexOf(fileEndWith) != -1){
// some code.....
}
});
});
but it is giving error, Can't resolve fs.