如何在Node.js repl中禁用.save命令?

时间:2015-10-12 06:49:33

标签: node.js

我是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仍然生成命令行历史文件。

1 个答案:

答案 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