Adding external libraries to postman

let a = (res) => new Function(pm.variables.get(res))
pm.sendRequest("https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.33/moment-timezone-with-data-2012-2022.min.js", (err, res) => {
    pm.sendRequest("https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js", (err2, res2) => {

        pm.environment.set("res2", res2.text());
        pm.environment.set("res", res.text());

        eval(pm.environment.get("res2"));
        eval(pm.environment.get("res"));


        console.log(this.moment.utc().tz("America/Los_Angeles", "UTC").format())


    })
})

use min build instead as it won’t mess up global space. you just have to call eval on the response to use it and then use this.

now to reuse the code you just have to use :slight_smile:

eval(pm.environment.get("res2"));
eval(pm.environment.get("res"));


console.log(this.moment.utc().tz("America/Los_Angeles", "UTC").format())

Hi @praveendvd,

Just a thought, if we directly save the js data in global/collection/environment variable.

then can we use the eval function on that?

1 Like

Yes yes you can do that :smiley:, you just have trigger momentjs first to make moment timezone work

1 Like

Thanks, This worked for me. But copying the code gave me the wrong quotes and it added a 59 to the code.