How do I make a postman package script globally available without importing it into each script?
I wanted to be able to create a package library, and make it available for usage without having to import it into each and every script.
QUESTION: I figured out a way, but I was hoping there was a cleaner way. Is anyone aware of a way that would make pm.require global?
The method I figured out:
The package library:
function HelloWorld() {
console.log('Hello World');
}
function GoodMorning(name) {
return `Good morning ${name}`;
}
module.exports = {
HelloWorld,
GoodMorning
}
The collection level script:
const myUtils = pm.require('@myteam/utils');
// wrap the library functions as a global so we dont have to import the library into every request.
utils = {
HelloWorld: function() {
myUtils.HelloWorld();
},
GoodMorning: function(name) {
console.log(myUtils.GoodMorning(name));
}
};
// now any scripts under this collection can use these functions without having to import the package;