azat-co / expressworks

Learn Express.js from the author of one of the best books on Express.js—Pro Express.js— with this workshop that will teach you basics of Express.js.
MIT License
709 stars 220 forks source link

Jade challenge Error. #113

Closed ar5had closed 8 years ago

ar5had commented 8 years ago

Code

var express = require("express");
var app = express();
var path = require("path");
app.set('views', path.join(__dirname,"views"));
app.set('view engine', 'pug');
app.get('/home',function(req, res){
   res.render('index', { date : new Date().toDateString() }); 
});
app.listen(process.argv[2]);

Error message

Error: Failed to lookup view "index" at Function.app.render (/home/ubuntu/workspace/node_modules/express/lib/application.js:495:17) at ServerResponse.res.render (/home/ubuntu/workspace/node_modules/express/lib/response.js:756:7) at /home/ubuntu/workspace/fcc-expressworks/jade.js:7:8 at callbacks (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:161:37) at param (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:135:11) at pass (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:142:5) at Router._dispatch (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:170:5) at Object.router (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:33:10) at next (/home/ubuntu/workspace/node_modules/express/node_modules/connect/lib/proto.js:190:15) at Object.expressInit as handle Error: Failed to lookup view "index" at Function.app.render (/home/ubuntu/workspace/node_modules/express/lib/application.js:495:17) at ServerResponse.res.render (/home/ubuntu/workspace/node_modules/express/lib/response.js:756:7) at /home/ubuntu/workspace/fcc-expressworks/jade.js:7:8 at callbacks (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:161:37) at param (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:135:11) at pass (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:142:5) at Router._dispatch (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:170:5) at Object.router (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:33:10) at next (/home/ubuntu/workspace/node_modules/express/node_modules/connect/lib/proto.js:190:15) at Object.expressInit as handle

Versions

npm - 2.14.4 node - v4.1.2 express - express@3.2.6

TylerMoeller commented 8 years ago

I don't think ExpressWorks has been updated for Pug yet - it's still using Jade. Remove the path code (lines 3-4), change the view engine to Jade, and then change 'index' to process.argv[3] to let Expressworks point at the template you need.

var express = require('express');
var app = express();
app.set('view engine', 'jade');
app.set('views', process.argv[3]);
app.get('/home', function (req, res) {
  res.render('index', { date: new Date().toDateString() });
});

app.listen(process.argv[2]);

Please reply back with any errors.

ar5had commented 8 years ago

@TylerMoeller Thanks man! it worked.