2015-10-12 37 views
0

我是Node.js的新手。我剛剛讀取了REPL api,我假定設置環境變量NODE_REPL_HISTORY""將關閉生成命令行歷史文件的.save命令。我錯了嗎?如何在Node.js中禁用.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

你能嘗試* *前移動環境變量設置了'repl.start':

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手動刪除它刪除這個命令? – poke

+0

不幸的是,它不工作 –

+0

太糟糕了:(嗯,值得一試 – poke

回答

0

.save命令是definedlib/repl.js無條件地,即它是存在的,不管任何環境變量。

delete replServer.commands.save; 
+0

謝謝,我不再懷疑是否存在'.save'關於環境變量。 –