有没有办法在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' >
- Bundle.js不是在命令节点之后创build的
- 从node.js中获取错误Uncaught ReferenceError:模块未定义,未捕获ReferenceError:require未定义
- AngularJS:无法发送POST请求与适当的CORS头
- 用于JSON缩小的UglifyJs JavaScript API?
- 如何知道一个函数是否是asynchronous的?
- npm无法构buildsocket.io,错误“与您的节点版本/ npm:commander@0.5.0不兼容”
- 如何解释执行结果不同于节点和浏览器
- file upload和谷歌Protobuf
- 在Javascript中通过一系列承诺传递状态的模式是什么?