Looking for a clean way to share code

Currently, I have almost 1400 lines of JavaScript divided among 6 “library” requests, which load the library code into global variables.

Some of those libraries are generic in nature, some are project specific. Having the project-specific library code in Global means I’m polluting the variables used for other projects. That’s a bad practice.

Each project also has at least 4 environments. So storing in the Environment variables is not wise, either.

If I could programmatically write those libraries to the collection variables, that would be ideal. Then, they would only be available where they are needed, and not getting the way of other projects. However, looking at the docs, it seems to imply that you can’t programmatically write to the collection or folder variables.

I’m not too keen on duplicating code by pasting the 1400 lines into the collection script. When other collections need some but not all of the code, that becomes a maintenance nightmare.

What I need is the ability to require('...'), be it files on the file system, or in a particular location within the collection, so that I can make my library code as modular as I like without violating best practices and without making things excessively complicated.

Does there exist some little-known feature that will let me do what I need to do? For example, is there a way to programmatically populate the collection variables that isn’t documented?

1 Like

@jarrowwx

Are these 1400 lines of JavaScript all functions that you use in various pre-req and test scripts ?