unable to load and eval javascript code in postman pre-request

Viewed 28

I am trying to load external javascript in the pre-request tab of postman request by following the steps mentioned in https://blog.postman.com/adding-external-libraries-in-postman/ but seems like it is not working. Below is the code I am trying and it is not loading. I am not sure what is wrong and what is not working

pm.sendRequest("https://cdnjs.cloudflare.com/ajax/libs/chance/1.1.8/chance.min.js", (err, res) => {
   //convert the response to text and save it as an environment variable
   pm.collectionVariables.set("chancejs_library", res.text());
   eval(pm.collectionVariables.get("chancejs_library"));
   console.log(this.chance().string()) // --> not working
   console.log(this.chance()) // --> not working
   console.log(this.Chance()) // --> not working
   console.log(this.Chance().string()) // --> not working
})

In all the above cases, I get the same error

ReferenceError: chance is not defined
0 Answers
Related