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

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

而不是这样做:

$ node file.js

这将执行脚本,但会closures节点壳后…

是否有执行已经在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 

只是做一个需求!

例如:file.js:

 console.log( "SCRIPT RUNNING" ); module.exports = "optional return"; 

要求从壳

 $ node > myresult = require( "./file.js" ) SCRIPT RUNNING 'optional return' >