我是Node.js的新手。我刚才正在阅读REPL
api,我假设设置环境变量NODE_REPL_HISTORY
到""
将关闭.save
命令,该命令会生成命令行历史文件。我错了吗?
所以我决定用process
模块设置它:
var repl = require("repl");
process.env['NODE_REPL_HISTORY'] = "";
var replServer = repl.start({
prompt:"my-app > ",
});
console.log(process.env);
var add = function(a,b){
return a+b;
};
replServer.context.foo = "bar";
replServer.context.add = add;
不幸的是,REPL仍然生成命令行历史文件。
答案 0 :(得分:0)
.save
命令lib/repl.js
无条件repl.defineCommand('save', {
help: 'Save all evaluated commands in this REPL session to a file',
action: function(file) {
try {
fs.writeFileSync(file, this.lines.join('\n') + '\n');
this.outputStream.write('Session saved to:' + file + '\n');
} catch (e) {
this.outputStream.write('Failed to save:' + file + '\n');
}
this.displayPrompt();
}
});
,无论环境变量如何,它都会出现。
replServer
您可以通过从delete replServer.commands.save;
:
-1