S
S
Stopy2015-04-17 13:05:25
Node.js
Stopy, 2015-04-17 13:05:25

Node.js can't render view. Why does this error appear?

c:\node\b\views\main.jade:1
unction (exports, require, module, __filename, __dirname) { doctype html(lang=
                                                                    ^^^^
SyntaxError: Unexpected identifier
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (c:\node\b\controllers\Main_Controller.js:5:17)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)

Controller code:
var Main_Model = require('../models/Main_Model.js');
var Main_View = require('../views/main.jade');

module.exports = function (req, res, db) {
    Main_Model.getData(db, function(data) {
     		res.render('../views/main.jade', data);
    });
}

Here is what the model returns:
var Main_Model = {
    getData: function(db, callback) {
     		var col = db.collection("users");
     		var data = {title: 'title', text: 'text'};
     		callback(data);
  	}
};

module.exports = Main_Model;

Here is the processing of the request itself:
app.get('/', function(req,res,next) {
    Main_Controller(req, res, db);
});

Where is the mistake?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Kitmanov, 2015-04-17
@Stopy

You are trying to request a template for some reason: var Main_View = require('../views/main.jade');
node.js tries to interpret it as JS, hence the error.

V
Vyacheslav Onufriev, 2015-04-17
@zloyded

Unexpected identifier - undefined identifier?
There is an error in the syntax, like a template.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question