0

I have an Electron application that uses:

  • React for the frontend

  • Node + Express backend inside /Server

  • A SQLite database stored inside the same /Server folder

During development, everything works correctly.
Running:

npm start

starts Electron, and the server is required inside main.js like this:

require("./Server/index.js");

The React build is loaded from client/build/index.html, and API calls work normally.


Problem

When I package the app using:

npm run dist

The application UI opens, but the backend server does not run, and all API calls from React stay in Pending. The SQLite database is also not found.

So the packaged app runs only the UI, without the server.

Electron Builder also gives warnings like:

asar usage is disabled — this is strongly not recommended

And if I enable asar, the SQLite DB becomes inaccessible.


What I understand so far

  • The server and .sqlite file cannot work properly when bundled inside app.asar.

  • They need to be unpacked to the real filesystem (e.g., resources/server/).

  • The server entry path should change depending on development vs production.


Current build section in package.json

"build": {
  "appId": "com.yourcompany.matjari",
  "files": [
    "main.js",
    "Server/**",
    "client/build/**"
  ],
  "asar": false
}

Question

What is the correct Electron Builder configuration to:

  1. Include the /Server folder and the SQLite database in the packaged app

  2. Ensure the server runs when the app is built (.exe)

  3. Allow the database to be writable and accessible at runtime

Should I use "asar": true and asarUnpack?
Should the database be moved to a different directory such as resources/?
What is the recommended structure for Electron apps that include a backend server and SQLite?


Goal

I want the packaged app (.exe) to:

  • Start the Express server automatically

  • Load and use the SQLite database normally

  • Keep everything inside the installation folder (no external installs required)


Thanks in advance to anyone who has solved this setup before.

2
  • Yes, some applications can run as Electron application, but not in packaged form. I faced two issues. 1) Under Electron, an application can use some resources outside its root directory. In the packaged form, all source code and resources goes in the subdirectory resources, packed in asar or not. Your application may use something outside this directory. 2) If you use asar, some API can work with asar internal paths, some cannot. Commented Nov 13 at 6:21
  • Please note that Generative AI (e.g., ChatGPT) is banned and read Help Center: AI policy. Commented Nov 13 at 21:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.