Create exe file using pkg



  • Hello @jan_blaha @bjrmatos26

    I have downloaded the js report npm package and used that with the node app to generate a report, so , in summary, node app will get a request, process some database operation, and then with this data and template name report will be rendered.

    I have created one basic template named test which is just containing "<h1>Hello</h1>". we know this will be stored in the data folder of the root repository. and I have also included configuration file report settings. All things work fine when I am running on the local machine.

    Overall server.js file. [ when "/report" path will be called test report will be displayed]

    if (process.env.JSREPORT_CLI) {
     module.exports = jsreport
    } 
    else {
      jsreport.init().then(() => {
         // start here
       
      })
    }
    
    
    app.get('/report', (req, res) => {
    
      console.log("------ report endpoint is called -----")
    
     
      jsreport.render({
        template: {
          name: test,
          engine: 'handlebars',
          recipe: 'chrome-pdf'
        },
        data: {}
        
    
      }).then((result) => {
        
      
       console.log("-------------------------------------------------------", result.content,);
        
        res.send(result.content);
        
        
      })
    })
    

    Problem starts here:

    --> When I am trying to convert this app into an executable file using the pkg tool and following the command "pkg . --debug " the exe file is not able to render a template. As we know if we have to include a data folder in the executable file I have put it in the package.json file.

    In package.json file: (So templates should be inside exe file)

    "pkg": {
    "assets": [
    "./data/*/",
    ]
    }

    --> Error I am getting:

    (because) unable to find specified template (test)
    Error: Unable to find specified template (test)
    at C:\snapshot\reporting\node_modules@jsreport\jsreport-core\lib\shared\createError.js:10:13


  • administrators

    @sahil12197 creating an executable with pkg and jsreport source is not an easy task. there are details to take care and explaining all of them will take a lot of time, however, it is possible.

    the best i can do for you is to link to the source code we have for preparing the exe file we provide on each release.

    the source code is available here, you will need to analyze it and discover how it works, we can not offer some guidance there because explaining will take lot of time for us



  • As you suggested using the pkg tool it is hard to create an exe file, can you provide an alternative way to achieve my requirements?

    Thanks @bjrmatos26 in advance for your time and help.


Log in to reply
 

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