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

前端 未结 11 1634
执念已碎
执念已碎 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:31

    Why not load the file into an interactive node repl?

    node -h
    -e, --eval script          evaluate script
    -i, --interactive          always enter the REPL even if stdin
    
    node -e 'var client = require("./build/main/index.js"); console.log("Use `client` in repl")' -i
    

    Then you can add to package.json scripts

    "repl": "node -e 'var client = require(\"./build/main/index.js\"); console.log(\"Use `client` in repl\")' -i",
    

    tested using node v8.1.2

提交回复
热议问题