Marc Rasmussen
Marc Rasmussen

Reputation: 20565

Node with phantom no default engine was specified

I have the following node code:

    var express = require('express');
var app = module.exports = express();
var phantom = require('node-phantom');

    app.use('/', function (req, res) {
        if (typeof(req.query._escaped_fragment_) !== "undefined") {
            phantom.create(function (err, ph) {
                return ph.createPage(function (err, page) {
                    return page.open("https://example.com/#!" + req.query._escaped_fragment_, function (status) {
                        return page.evaluate((function () {
                            return document.getElementsByTagName('html')[0].innerHTML;
                        }), function (err, result) {
                            res.send(result);
                            return ph.exit();
                        });
                    });
                });
            });
        } else
            res.render('index');
    });

    app.listen(3500);
    console.log('Magic happens on port ' + 3500);

This happens whenever i attempt to go to my domain. However when i go there i get the following error:

Error: No default engine was specified and no extension was provided.

Can anyone tell me what im doing wrong?

Upvotes: 0

Views: 43

Answers (1)

James LeClair
James LeClair

Reputation: 1294

Express is trying to call render, but you didn't specify which view engine to use. That's what the error is

If you are using jade add this configuration after you invoke app

//change path to fit your use case of course
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');

If you are just trying to send a static html file, use res.sendFile() instead

res.sendFile('/path/to/index.html')

Upvotes: 1

Related Questions