JSReport in Electron

  • I've been working to get everything bundled up into Electron. At this point, I'm spawning node with jsreport from the main.js that starts the electron window. This works if the user has nodejs with electron globally but I haven't been able to get it packaged so that the end user won't need node installed. I get a jsreport server exception. (I'll post later)

    It's not a typical context as there aren't servers around.

    I'm just interested if anyone has packed everything else up into Electron?

  • administrators

    hi! i'm very interested in having jsreport to work in a packaged electron app, so far i don't have any recommendation to share but if you can make it work, please share here your solution. maybe we can do something in our side to improve this use case.

  • I'm not there yet. It will run at a command prompt, with the electron . from the base directory of my deploy folder.

    The deploy folder is set up with my angular webapp (angular-cli's built dist folder) at the root. then I arrange my data server one level down, and the report server as a sibling to my report server. A copy of node.exe gets put into the root, with main.js to launch the electron window. A special package.json, needs to be placed there for the electron dependency that the packaging tools use.

    From main.js, it effectively spawns the two nodejs processes that the webapp talks to. It does work. But I'm not fully packaged yet. I have no idea if this is a complete hack or not. I only found one github repo that does this sort of thing, with a number of references pointing to that same github repository. https://github.com/frankhale/electron-with-express

    To execute the electron . at the command prompt means that node needs to be installed, with electron installed globally. I'm working to eliminate this dependency. A fully packaged electron will not require this dependency. I get an exception when I get to this point that I haven't fully explored yet. Electron can also get packed to down to few files with the asar format. That's one step further.

    A big problem I have with the server side is logging, so far I haven't come up with a strategy to come get the console.log routed somewhere to where I can see it. I'm toying with a winston logger.

    A main.js (wip)

    const winston = require('winston');
    var _logger = new (winston.Logger)({
        transports: [
          new (winston.transports.Console)(),
          new (winston.transports.File)({ filename: './app.log' })
    _logger.level = 'debug' ;
    global.logger = _logger;
    _logger.debug("Starting Data Server");
    var server = require("./server/index.js")
    _logger.debug("Started Data Server");
    _logger.debug("Starting ReportServer");
    var rptServer = require("./reportserver/server.js")
    _logger.debug("Started ReportServer");
      // var child_process = require("child_process");
      // var process = child_process.spawn(".\\node.exe", ["./server/index.js"], {
      //   cwd: child_process.cwd 
      // });
      // process.stdout.on('data', function (chunk) {
      //     _logger.debug(chunk.toString());
      // });
        // spawn = require("child_process").spawn,
        //   // For electron-packager change cwd in spawn to app.getAppPath() and
        //   // uncomment the app require below
        //   //app = require('electron').remote.app,
        //   node = spawn(".\\node.exe", ["./server/index.js"], {
        //     cwd: process.cwd()
        //   })
    const electron = require("electron"),
      app = electron.app,
      BrowserWindow = electron.BrowserWindow;
    let mainWindow;
    function createWindow() {
      mainWindow = new BrowserWindow({
        autoHideMenuBar: true,
        width: 640,
        height: 480
      mainWindow.on("closed", function() {
        mainWindow = null;
      _logger.log('debug', 'before menu.js') ;
      _logger.log('debug', 'bottom of createWindow') ;
    app.on("ready", createWindow);
    app.on("browser-window-created", function(e, window) {
    _logger.debug('browser-window-created') ;
    app.on("window-all-closed", function() {
      if (process.platform !== "darwin") {
    app.on("activate", function() {
      if (mainWindow === null) {

    And a simple .json file that get's layed in for the electron packaging

      "name": "MyTestApp",
      "version": "0.1.0",
      "main": "main.js",
      "dependencies": {
        "electron": "^1.7.9",
        "remote": "^0.2.6",
        "winston": "^2.4.0"

Log in to reply

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.