1

I'm developing some really simple node.js libraries for learning purposes.

It's about functions like HexToBase64 and things like that.

Ideally, I'd like to program in a text editor, and play with it on the node repl, having the code automatically reloaded on the repl on every save.

Any module or tool to interactively play with node?

4

1 回答 1

1

有诸如supervisornodemonforever之类的模块可以在代码更改时重新加载您的应用程序。否则,您可以像这样创建自己的实现:

var fs = require('fs');
var cluster = require('cluster');

if (cluster.isMaster) {
  var worker = cluster.fork();

  fs.watch(process.argv[1], function(event, filename) {
    worker.kill();
    worker = cluster.fork();
  });
}

if (cluster.isWorker) {
  // put your application logic here that will
  // run when this file changes
}

至于交互式使用 Node,您可以node在终端中运行,并且您有一个交互式控制台。如果您需要加载脚本并以交互方式使用它,那么您将使用.load script.js.

于 2013-09-13T02:57:16.533 回答