fs.readFile find a placehold and replace, Handlebars js also an option if need be

Advertisements I currently load a file in node with fs.readFileSync: const filename = ‘test.html’; const html_code = fs.readFileSync(/var/www/vhosts/example.com/httpdocs/html/${filename}, ‘utf8’); in test.html I have this div: <div id="g-ai0-1" class="g-Text g-aiAbs g-aiPointText" style="top:59.6648%;margin-top:-14.2px;left:49.9587%;margin-left:-46px;width:92px;"> <p class="g-pstyle0">{{ Text }}</p> </div> Is there away I can search the html for the {{ Text }} string and replace it with something… Read More fs.readFile find a placehold and replace, Handlebars js also an option if need be

Fs throw error not a direcectory when path is good

Advertisements This is how function is looking and error code. Can someone see what I’m doing wrong? Here is code: for (const folder of functionFolders) { const functionFiles = fs .readdirSync(`./src/functions/${folder}`) .filter((file) => file.endsWith(‘.js’)); for (const file of functionFiles) { await import(`./src/functions/${folder}/${file}`); } } and error node:fs:1451 handleErrorFromBinding(ctx); ^ Error: ENOTDIR: not a directory, scandir… Read More Fs throw error not a direcectory when path is good

Read or select value names from .json file to push in the array

Advertisements if myjson.js file data: { "key1": [ { "name1": [ "word1", "word2", ], "name2": [ "word3", "word4", ] } ] } loaded: var jsonData = fs.readFileSync("myjson.json", "utf8"); const data = JSON.parse(jsonData); console.log(Object.keys(data)); output: [ ‘key1’ ] or: console.log(Object.values(data)); output: [ [ { name1: [Array], name2: [Array], } ] ] How properly read or select… Read More Read or select value names from .json file to push in the array