Shared Script
-
I currently have the following same config at the top of every one of my scripts:
const config = { "user": "username", "password": "password", "server": "localhost", "database": "DatabaseName", "options": { "encrypt": true } };
The location of my database and username and password has changed a bunch of times and it's a real pain to go into every script file to update this. Is there a better place I can put this so all the scripts have access to config and I only need to update one file?
-
One option is to use environment variables to reach connection strings
https://jsreport.net/learn/scripts#environment-variables-and-configurationAnother option is to create one script and mark it as global.
It will run every time and you can set the connection string toreq.options.connectionString
for example and reach it there in your other scripts.
https://jsreport.net/learn/scripts#global-scriptsThe third option is to use assets, store there a json with a connection string, and embed it to every script.
let connectionString = "{#asset connectionString.json @encoding=string}"
https://jsreport.net/learn/assets