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
715 stars 220 forks source link

Jade - missing directory #99

Closed bessieatrazoyo closed 8 years ago

bessieatrazoyo commented 8 years ago

When I tried my code, I got this error:

5082Error: Failed to lookup view "index" in views directory "/Users/razoyo-dev/NodeSchool/templates"

Is this one my fault?

Here's my code:


var http = require('http');
var express = require('express');
var path = require('path');
var app = express();

app.set('view engine', 'jade');
app.set('views', path.join(__dirname, 'templates'));
app.get('/home', function (request, response) {
  response.render ('index', {date: new Date().toDateString()});
  response.end(process.argv[2]);
});
app.listen(process.argv[2]);
azat-co commented 8 years ago

hint: app.set('views', path.join(__dirname, 'templates'));

bessieatrazoyo commented 8 years ago

Thanks for trying to help me, but what did you mean? I already had that line in my code

app.set('views', path.join(__dirname, 'templates'))

which is what the directions told me to do. Where you telling me to do that, too?

What did work was this:

app.set('views', process.argv[3]);

I think these directions are a bit confusing:

This is how you can specify the path to the template files in the folder templates:

app.set('views', path.join(__dirname, 'templates'))
azat-co commented 8 years ago

@bessieatrazoyo

This is you can specify folder name in general, meaning example:

app.set('views', path.join(__dirname, 'templates'))

But you need to have specific code to solve the problem:

app.set('views', process.argv[3]);
bessieatrazoyo commented 8 years ago

Oh, ok. My apologies for being this dense. ExpressWorks is such a great tool for learning, but I'm struggling regardless. I will get it in the end!

azat-co commented 8 years ago

@bessieatrazoyo I agree. To speed your learning, you can read my blog posts for FREE at http://webapplog.com, just do search for the topic... or get Pro Express.js