我是 Node.js 的新手,我想知道是否有一种方法可以从 Node shell 内部执行 JavaScript 文件。让我这样解释:

而不是这样做:

$ Node 文件.js

这将执行脚本,但随后将关闭 Node shell...

有没有办法执行已经在 Node shell 中的脚本?像这样的东西:

$ node 
> file.js                  # We're now inside the Node.js shell 
 
... script execution... 
 
>                          # already inside the shell,  
                           # then being able to access to script variables 

请您参考如下方法:

Node.js Shell 中执行以下命令:

.load foo.js 


评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!