I need to execute some js files one after another, those js files are printing important information in the console.log.
I'm currently trying to use the following code, but it is not showing the console.log for sub js files.
How can I get this approach to work?
const fs = require('fs')
const exec = require('child_process').exec
const async = require('async') // npm install async
const path = require('path');
const scriptsFolder = path.resolve("./") + "\\" named scripts
const files = fs.readdirSync(scriptsFolder)
const targetFiles = files.filter(function (file) {
return path.extname(file).toLowerCase() === '.js';
});
const funcs = targetFiles.map(function (file) {
return exec.bind(null, `node ${scriptsFolder}${file}`)
})
function getResults(err, data) {
if (err) {
return console.log(err)
}
const results = data.map(function (lines) {
return lines.join('')
})
console.log(results)
}
async.series(funcs, getResults)