在新的terminal中启动带有child_process的Node.js Express服务器

我正在寻找一种方法来启动一个Node.js高速服务器使用分离的child_process,我想stream输出到一个新的terminal窗口。 这可能与Node.js不知何故?

所以我有这个:

//server.js var http = require('http'); const PORT=8080; function handleRequest(request, response){ response.end('It Works!! Path Hit: ' + request.url); } http.createServer(handleRequest).listen(PORT, function(){ console.log("Server listening on: http://localhost:%s", PORT); }); 

然后我想通过运行这个文件启动该服务器

 //start-server.js var cp = require('child_process'); cp.fork('./server.js'); 

我想打开一个新的terminal,然后运行start-server.js文件…这可能吗?

 var exec = require('child_process').exec, child; child = exec('gnome-terminal -x node', function (error, stdout, stderr) { console.log('stdout: ' + stdout); console.log('stderr: ' + stderr); if (error !== null) { console.log('exec error: ' + error); } }); 

在node命令之后添加file_name,它总是会在运行节点js之前启动新的terminal

参考: – https://askubuntu.com/questions/401009/command-to-open-new-terminal-window-from-the-current-terminal/401012

https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

结合这两个想法