How to npm install using jsreport online?



  • Hi! I was wondering how do you install modules like Nodemailer or Sendgrid using jsreport online. I can't for the life of me find how to do it on the web UI.

    I'm assuming most of the examples i've seen are directed towards having your own installation of JSReport to add said modules into your config.
    Please advise, unsure how to proceed.



  • Hi,
    unfortunately there is no way to install additional modules to jsreportonline.
    You can use only modules we provide to the global audience there.

    The sendgrid or nodemailer are currently not included in the jsreportonline. We will evaluate this and I believe we will add them in the next release.



  • I see. I'm thinking of sending the report through the node js client then. We use it to call render on it anyway. Just need to figure out how to save and attach the buffer from response.pipe().

    What are your thoughts?



    1. I forgot to mention that the sengrid has also REST API. So it is quite easy to use request module in jsreportonline and send the email to sengrid. Without a need for extra module.

    2. Here you can find a code how to get the buffer from the nodejs client. https://jsreport.net/learn/nodejs-client#rendering-reports



  • For anyone else using the nodejs-client and want to save the pdf to disk instead of passing it through the response object in express, here's a snippet to help out.

    Im not familliar with streams so this took me a while to get it right. I hope this helps someone :D

    response.body(function(body){
          fs.writeFile('hello.pdf', body, function(err){
            if (err) console.log(err)
    
            res.send('ok')
    
          })
        })
    

    Wow you can even put the stream directly to the mail object for nodemailer

    response.body(function(body){
          var mail = {
            from: "Jan Blaha <test@gmail.com>",
            to: data.sendTo,
            subject: "Sending email from node.js",
            text: "See the attached report",
            html: "<b>See the attached report</b>",
            attachments: [
            {
                filename: 'Report.pdf',
                content: body
            }],
          }
    
          smtpTransport.sendMail(mail, function(error, response){
              smtpTransport.close();
              if(error){
                  console.log(error)
              }
    
              res.send('ok')
          });
        })
    

    thanks Jan


Log in to reply
 

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