run app.render asynchronously

Is there a way to run app.render asynchronously?

I tried promisifying it using bluebird but I get an error

    let render = Promise.promisify(req.app.render);
    html = await render('email', { email: 'someone@gmail.com' });

output:

TypeError: Cannot read property 'cache' of undefined

Author: Fantashit

1 thought on “run app.render asynchronously

  1. Okay, that link points to res.render instead of app.render, but it pointed my into the right direction.
    When I made render into it’s own variable, it lost the reference to this, so in order to fix it, you would

        const Promise = require('bluebird');
    
        req.app.renderAsync = Promise.promisify(req.app.render);
        let html = await req.app.renderAsync('email', { email: 'someone@gmail.com' });
    

    That actually works, thanks @fredski02

Comments are closed.