Node.JS 中的热交换。可能的?

ade*_*ago 12 javascript node.js

是否可以在 Node.JS 中实现或至少模拟代码热交换?如果是,如何?

热插拔(通常称为热插拔)是在不停止或关闭系统的情况下更换或添加组件。Erlang 和 Lisp 原生支持热插拔。

Gir*_*rpa -2

是的,您可以eval在 Node.js 中使用热插拔代码。

let fn = () => console.log('foo');
fn(); // foo
eval(`fn = () => console.log('bar');`); // hot swap the source of fn
fn(); // bar
Run Code Online (Sandbox Code Playgroud)