Answer the question
In order to leave comments, you need to log in
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)
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);
});
}
var Main_Model = {
getData: function(db, callback) {
var col = db.collection("users");
var data = {title: 'title', text: 'text'};
callback(data);
}
};
module.exports = Main_Model;
app.get('/', function(req,res,next) {
Main_Controller(req, res, db);
});
Answer the question
In order to leave comments, you need to log in
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.
Unexpected identifier - undefined identifier?
There is an error in the syntax, like a template.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question