启动Electron App后自动运行Node.js服务器文件 [英] Run Node.js server file automatically after launching Electron App
本文介绍了启动Electron App后自动运行Node.js服务器文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Node.js
作为服务器,我的问题是我不知道如何在启动电子应用时运行文件 server.js
p> 我想将我的应用程序打包为发行版,以便我可以在不使用命令行的情况下运行服务器 $ node server.js
。
解决方案
/ code>主文件中的 server.js
文件(例如 app.js
): p>
var app = require(app)
,server = require(./ server)
;
并且在服务器.js
您可以拥有的文件:
require(http)。createServer(function(req ,res){
res.end(从电子应用程序启动的服务器发出的问候!);
})。listen(9000)
Im using GitHub Electron to create Desktop application with web technologies.
I'm using Node.js
as the server, my problem is that i don't know how to run the file server.js
just when launching the electron app.
I want to package my app for distribution so that i can run the server without the command line $ node server.js
.
解决方案
Just simply require
the server.js
file in your main file (e.g. app.js
):
var app = require("app")
, server = require("./server")
;
...
And in the server.js
file you can have:
require("http").createServer(function (req, res) {
res.end("Hello from server started by Electron app!");
}).listen(9000)
这篇关于启动Electron App后自动运行Node.js服务器文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文