How To Package Express Server Inside Electron App?
I am currently building electron app with vue-cli-electron-builder . I have mysql local database and express server. How do I bundle express server and Electron app? I have used
Solution 1:
In background.ts
, you can import { fork } from 'child_process'
.
And put server.js
in /public/
.
import { fork } from'child_process'const isDevelopment = process.env.NODE_ENV !== 'production'const serverProcess = fork(isDevelopment
? path.resolve(__dirname, "../public/server.js")
: path.resolve(__dirname, "server.js"))
try {
serverProcess.stdout!.on("data", console.log)
serverProcess.stderr!.on("data", console.error)
} catch(e) {}
I have done it with vue-cli-electron-builder
at some time as well, but it conflicts with Reveal.js, so I did it manually.
However, regarding MySQL, you shouldn't put .env
or credentials in Electron, as people can reverse engineer it, needing a separate web server.
Post a Comment for "How To Package Express Server Inside Electron App?"