简体   繁体   中英

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!

Always use the path module to join paths.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM