Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
662 views
in Technique[技术] by (71.8m points)

github - Run Node.js server file automatically after launching Electron App

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...