How do I load my script into the node.js REPL?

前端 未结 11 1633
执念已碎
执念已碎 2020-11-30 17:59

I have a script foo.js that contains some functions I want to play with in the REPL.

Is there a way to have node execute my script and then jump into a

11条回答
  •  半阙折子戏
    2020-11-30 18:16

    Another suggestion that I do not see here: try this little bit of code

    #!/usr/bin/env node
    'use strict';
    
    const repl = require('repl');
    const cli = repl.start({ replMode: repl.REPL_MODE_STRICT });
    cli.context.foo = require('./foo'); // injects it into the repl
    

    Then you can simply run this script and it will include foo as a variable

提交回复
热议问题