节点REPL“退出”事件
有什么办法可以触发用户.exit
或[Ctrl] [D]脚本时调用的函数吗?
就像是:
repl.start().on('exit', function() { console.log("Thanks for using customized Node REPL!"); });
(除了当然,我实际上把有用的代码,而不是console.log
。)
repl.start().rli.on('close', function() { console.log("Thanks for using customized Node REPL!"); });
REPL使用发出Close
事件的Readline
模块。 从文档:
事件:'close'
function () {}
每当stream中收到一个
^C
或^D
,分别被称为SIGINT和EOT,就会发出。 这是知道用户完成使用您的程序的好方法。