[英]Start Node.js Express server with child_process in new terminal
我正在寻找一种方法来使用分离的child_process启动Node.js Express服务器,我想将输出流式传输到新的终端窗口。 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');
我想打开一个新终端,然后运行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之前启动新终端
https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback
结合这两个想法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.