2017-09-23 8 views
0

저는 Node.js를 처음 사용하고 Express 프레임 워크에 대해 학습했습니다. 그러나 나는 다시 너무 자극적 인 오류에 갇혀있다. 템플릿 엔진 'EJS'를 사용하는 방법을 배우는 비디오 자습서에서 배우고 있으며이 오류를 만날 때까지 아주 간단한 프로그램을 평화롭게 만들었습니다.Express 프레임 워크 오류

TypeError: Cannot read property '_locals' of undefined 
at EventEmitter.render 
(G:\Docs\Node.js\node_modules\express\lib\application.js:549:11) 
at G:\Docs\Node.js\app.js:6:9 
at Layer.handle [as handle_request] 
(G:\Docs\Node.js\node_modules\express\lib\router\layer.js:95:5) 
at next (G:\Docs\Node.js\node_modules\express\lib\router\route.js:137:13) 
at Route.dispatch 
(G:\Docs\Node.js\node_modules\express\lib\router\route.js:112:3) 
at Layer.handle [as handle_request] 
(G:\Docs\Node.js\node_modules\express\lib\router\layer.js:95:5) 
at G:\Docs\Node.js\node_modules\express\lib\router\index.js:281:22 
at Function.process_params 
(G:\Docs\Node.js\node_modules\express\lib\router\index.js:335:12) 
at next (G:\Docs\Node.js\node_modules\express\lib\router\index.js:275:10) 
at expressInit 
(G:\Docs\Node.js\node_modules\express\lib\middleware\init.js:40:5) 

그리고 내 코드는 이것이다 : -

var express = require('express'); 

var app = express(); 
app.set('view engine', 'ejs'); 
app.set('views', __dirname, '/templates'); 
app.get('/', function(req, res) { 
app.send("Welcome to the Homepage"); 
}); 
app.get('/profile/:name', function(req, res) { 
app.render('profile'); 
}); 
app.listen(4242); 
console.log("Server is running ...."); 

내가 현재 디렉토리에 존재하는 템플릿 폴더에 profile.ejs 파일을 만든 내가 127.0.0.1/ 입력 할 때 나는 것을 원하는 4242/profile/anyname 해당 프로필 페이지가 렌더링되고 표시되어야합니다.

내 Profile.ejs 페이지입니다 : 내가 다른 곳에서 정확한 답변을 찾을 수없는

<!DOCTYPE html> 
<html> 

<head> 
<title>Profile</title> 
</head> 

<body> 
<h1>Welcome to the Profile !!</h1> 
</body> 

</html> 

.

답변

0

이 같은

app.get('/profile/:name', function(req, res) { 
    res.render('profile'); // see the change here for *res* 
}); 
+0

Thaank 당신 그래서 김 많은 것을보십시오! 정말 나를 위해 일했습니다 :) – Pranshu