jsreport init and render problem, when to init jsreport using nodejs and createServer



  • Hi, i'm using jsreport for a small task.
    Having templates file to read, i first read all the files, store them in vars, then starting the rendering.

    .then(fileContent => {
            jsreport.init().then(() => {
              jsreport.render({
                template: { ... }
    

    All of this is inside:

    http
      .createServer((req, res) => {
    

    So everytime a request comes to the node server it tries to re-initiate jsreport, giving me errors, of course.
    I removed the piece where i init jsreport, leaving only the render.
    It works now.
    What i wanted to ask is, would be possible to initiate jsreport before the server, and then use jsreport.render() only when the server is called?

    I tried putting

    const jsreport = require('jsreport')().init();
    

    at the start, but then jsreport.render doesn't work.

    Appreciate your help,
    Thanks



  • You can do something like

    const jsreport = require('jsreport')()
    
    jsreport.init().then(() => {
      // the rest of your app init
      http.createServer....
    })
    


  • Hi @jan_blaha , i tried that, and it works well.
    Is it normal that for the first rendering request it takes almost the triple of time than the second request?
    Thanks again!



  • It depends on the configuration.
    Anyway, if this is an issue for you.
    Make the first rendering during the application initialization as a warmup procedure.



  • This post is deleted!

Log in to reply
 

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