且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

启动Electron App后自动运行Node.js服务器文件

更新时间:2023-08-23 23:12:58

/ 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)