user4002542
user4002542

Reputation:

Configure routes in node.js

I'm stuck on it since Friday, please.. somebody help me!!!

I have this route in my app.js:

app.get('/', function(req, res) {
    res.render('login', {
        user: req.user
    });
});

He is rendering the layout inside the views folder, which is inside the server folder.

I have this configuration in my app.js:

app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');

It's not working put:

app.set('views', __dirname + '../public');

Because it's searching like this:

"app/server../public"

and i need this:

"app/public"

Please, if someone know fix this, please help me!

Upvotes: 0

Views: 160

Answers (1)

nickclaw
nickclaw

Reputation: 698

Always use the path module to join paths.

var path = require('path');
var uri = path.join(__dirname, '../public');

Upvotes: 1

Related Questions