jeudi 13 août 2015

wait for css_parser.getCSSFiles()

I want to render page when CSS will be loaded. Function css_parser.getCSSFiles() reads file asynchronously and sends CSS content to variable css.cssFile . How I can force res.render to wait for end of file reading?

router.get('/main', function(req, res) {

    css_parser.getCSSFiles();
    app.locals.css = css.cssFile;

    res.render('ua', {
        css: app.locals.css,
    });

});

UPDATE: So basically, I want to read also other kind of files. getJSFile is similar to getCSSFiles and I also initialize it before res.render

getJSFile: function(directory, file, variable) {
    fs.readFile(directory + file, 'utf8', function(err, data) {
        if (err) {
            return console.log(err);
        }
        variable.push(data);
});



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire