Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 601
Samir Ait Avatar asked Dec 24 '15 22:12

Samir Ait


People also ask

How do I permanently run node js server?

js application locally after closing the terminal or Application, to run the nodeJS application permanently. We use NPM modules such as forever or PM2 to ensure that a given script runs continuously. NPM is a Default Package manager for Node.

Does Electron run on a server?

Electron will open a window with "Application Electron and Express" as a title. The Express server will run on the background. To check if the server is active, open your browser and go to http://localhost:3000 . You will see a message: "Server is ready!"


1 Answers

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)
like image 184
Ionică Bizău Avatar answered Oct 18 '22 03:10

Ionică Bizău