[英]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.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. 他正在服务器文件夹内的views文件夹内渲染布局。
I have this configuration in my app.js: 我的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. 始终使用
path
模块来连接路径。
var path = require('path');
var uri = path.join(__dirname, '../public');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.