I have a \"library\" of objects that I want to load on the fly from a database. Each object comes with its own special functions that are called at specific times depending
You can only really serialise a whole file with require
calls in it. If you do that, you can create a module, exports and module.exports, eval the file with a function surrounding it and snag the module.exports out of it.
It's not exactly secure, but for that you need to use something like VM2 and value-censorship (which I've been working on) to avoid them calling eval() and owning your machine or the entire network.