Search code examples
angularexpresselectronweb-deploymentnwjs

Deploy/run: local Express web-server and local client-side angular app that sends ajax requests to this local web-server


I have:

  1. A node express-based web-server that should be running only on the user's local machine
  2. An angular client application, that sends GET Http requests to that local web-server to get data in JSON and display it on the browser

In my dev environment I start these as follows:

  1. npm run dev (on the directory of the express web server). It produces: "Express server listening on port 7000" and is ready to receive requests
  2. npm start (on the directory of the client application). This launches the client app in the browser. Then I can type, click buttons and get data (from the web-server) displayed.

I want to provide this system to an end user in a convenient way for them:

  1. The target environment is Windows. Ideally they should run a single installation (such as from an .msi file).
  2. When the installation is complete, they should be able to start the system (both the web-server and the client application) with a single command.
  3. The end user is not supposed to know anything about node, npm, .. etc, neither should they know the home directories of the two components -- in fact they may not be even aware that a local express web-server is being used.

What is important is not only a convenient installation, but then to be able to start both system components with a single user command. When the user closes the client application, ideally the express web-server should also be closed.

I played with electron.js, but it seems it will not deploy and start the express server that is needed by the electron application. Also read about nw.js but haven't seen any example similar to my scenario.

I know that maybe??? I can implement the server-side as one of the electron renderer processes and, instead of HTTP, use inter-process communication (IPC) to communicate with the client-app (another renderer process) involving the main process in this. However, this would require substantial reworking of this already existing system, which would need significant time and is not affordable at present.

Is the deployment and usage scenario (1, 2, 3 above) possible and what are the best tools to use for implementing such deployment and execution scenario?

Could you provide reference(s) to any such implementations? And/or ideally small/complete code examples?


Solution

  • Yes you can do it. Yo can pack both electron app and express server in the production. In developing you need to develop the express app and execute it using nodejs child-process module. Here you can use exec command or spawn command ( i prefer exec, easy to use). The you can start the express process from you electron main process. Wait till the express server setup and then move on with the app.

    And for the puppeteer I suggest you to take a look in this github thread . They are saying to execute puppeteer on the main process and communicate the main and renderer processes by electron IPC

    For building windows installer I think its better to use electron-builder and generate a nsis installer with a signed certificate