有没有办法在Node.js shell中运行JavaScript文件?

cha*_*nie 6 javascript shell node.js

我是新手Node.js,我想知道是否有一种JavaScript从Node shell 中执行文件的方法.让我用这种方式解释一下:

而不是这样做:

$ node file.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
Run Code Online (Sandbox Code Playgroud)

cha*_*nie 11

Node.jsShell中执行以下命令:

.load foo.js
Run Code Online (Sandbox Code Playgroud)