Hello there!
I'm not sure I got the question right, but I think I understood the main parts, and hopefully what follows should help you getting started. The main part is the REPL API from NodeJs.
In the sample below, I'll create 2 dumb modules in which I define custom functions, then I write some repl bootstrap to customize the way the interactive NodejS (its repl) is launched, and we'll see my modules are loaded automatically:
Let's start with the modules we want to load:
moduleA.js
'use strict';
exports.echo = (a) => console.log(`echo from A ${a}`);
moduleB.js
'use strict';
exports.add = (a, b) => a + b;
Then the magic happens here, in the bootstrap repl:
repl.js
const repl = require('repl').start({useGlobal: true});
for (let myModule of ['moduleA', 'moduleB']) {
repl.context[myModule] = require(`./${myModule}`);
}
(To keep things simple all these files are in the same folder, but you're free to complexify this at will)
Now, rather than just typing $ node to enter the repl console, use that bootstrap script:
$ node repl.js
And now you're in the interactive shell, as usual, but moduleA and moduleB are alreayd loaded :
> moduleA.echo('test')
echo from A test
> moduleB.add(2, 3)
5
You can even add a #!/usr/env/bin node and do a chmod +x repl.js to call ./repl.js directly and enter your customized interactive shell.
I hope I understood your question correctly, Hope this helps, Séb
Sébastien Portebois
Software architect at Ubisoft