Thank you , this is my code for anyone with same problem :
This is work for me
Javascript :
const path = require('path')
const fs = require('fs')
function beforeRender(req, res, done) {
//file location, file name
const configPath = path.join("E:\\Program\\", 'sample.json')
// any message called with console.log, console.warn, console.error will be saved into logs
console.log('reading custom file..')
//testing file location
console.log('from : '+configPath)
//read file json
fs.readFile(configPath, (err, content) => {
if (err) {
return done(err)
}
try {
req.data = Object.assign({}, req.data, JSON.parse(content.toString()))
/* const myconfig = JSON.parse(content.toString())
// use config values to apply some conditional logic in the script
if (myconfig.validateData) {
// .. your custom logic here ..
}
// or pass custom config as data to your templates
req.data.myconfig = myconfig
*/
done()
} catch (e) {
done(new Error('error while trying to parse custom config at ' + configPath + ': ' + e.message))
}
})
}
jsreport.config.json
{
"extensions": {
"authentication": {
"cookieSession": {
"secret": "<your strong secret here>"
},
"admin": {
"username": "sa",
"password": "Password1000"
},
"enabled": false
},
"scripts": {
"timeout": 40000,
"strategy": "http-server",
"allowedModules": ["path","fs"]
},
"sample-template": {
"createSamples": true
}
},
"httpPort": 5488,
"store": {
"provider": "fs"
},
"blobStorage": {
"provider": "fs"
},
"logger": {
"console": {
"transport": "console",
"level": "debug"
},
"file": {
"transport": "file",
"level": "info",
"filename": "logs/reporter.log"
},
"error": {
"transport": "file",
"level": "error",
"filename": "logs/error.log"
}
},
"allowLocalFilesAccess": true,
"templatingEngines": {
"timeout": 10000,
"strategy": "http-server"
},
"chrome": {
"timeout": 40000
}
}