如果不通过命令行运行脚本, Node 会自动进入 REPL 模式。我想退出 REPL 模式。 REPLServer类有一个 close
方法,但我无法调用它,因为我无权访问 repl.start 返回的实例哪个 Node 在内部使用(node.js第142行)来实现其REPL模式。我怎样才能退出 REPL 模式?
node.js 第 142 行概要:
// If -i or --interactive were passed, or stdin is a TTY.
if (process._forceRepl || NativeModule.require('tty').isatty(0)) {
// REPL
var opts = {
useGlobal: true,
ignoreUndefined: false
};
if (parseInt(process.env['NODE_NO_READLINE'], 10)) {
opts.terminal = false;
}
if (parseInt(process.env['NODE_DISABLE_COLORS'], 10)) {
opts.useColors = false;
}
var repl = Module.requireRepl().start(opts); // <<< line 142
repl.on('exit', function() {
process.exit();
});
} else {
// Read all of stdin - execute it.
process.stdin.setEncoding('utf8');
var code = '';
process.stdin.on('data', function(d) {
code += d;
});
process.stdin.on('end', function() {
process._eval = code;
evalScript('[stdin]');
});
}
最佳答案
关于javascript - 在没有实例的情况下结束 REPL 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20412513/