1

I am trying to make a desktop application with electronjs. Since nestjs makes the back-end development super-easy, I want to use it with electron.

Initially I tried to run the command

electron . && nest start

This makes the nest process start only after the electron app is closed.

I found only one video on youtube for this and no other proper solution elsewhere. link: https://www.youtube.com/watch?v=vWpybfpyzPI

I was having difficulty in understanding it.

I also wanted to know the possibility of smooth communication between electron and nestjs if I am able to achieve what has been achieved in the video. It doesn't seem like a standard thing to me.

Vivek Kumar
  • 11
  • 1
  • 3

1 Answers1

3

This is not easy but not impossible as well... I will assume that you are going to create some angular frontend application along with local nestjs api server... Then we can do this with following tricks...

  1. Create electron + angular app using xplat

  2. Create your local nestjs application.

  3. For production builds do the following trick.. a) In electron index.ts file add the following may be in create window function.

    if (!serve) { const { fork } = require('child_process'); const ps = fork(${__dirname}/main.js); }

    a.1) first build your Web Application. b) build your nestjs application and then copy nestjs node_modules plus nestjs dist into your angular dist. c) using electron_builder generate your packages and make sure electron builder will copy node_modules.. by default it will ignore it but we can pass some arguments to electron builder... by using package.json something like below...

    "files":[ "/*", { "from": "node_modules", "to": "node_modules", "filter": ["/*"] } ],

Note : for serving we dont need to run nestjs in electron all we need is to serve nestjs separately...

Dharman
  • 30,962
  • 25
  • 85
  • 135