Samir Ait
Samir Ait

Reputation: 331

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.

Upvotes: 17

Views: 29161

Answers (1)

Ionică Bizău
Ionică Bizău

Reputation: 113475

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)

Upvotes: 37

Related Questions