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

    Another option is to create one script and mark it as global.
    It will run every time and you can set the connection string to req.options.connectionString for example and reach it there in your other scripts.

    The 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}"

Log in to reply

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.