0
私はNode.jsを初めて使い、Expressフレームワークについて学習しています。 しかし、私は再び非常に刺激的なエラーで立ち往生しています。 私はTemplate Engine '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)
そして、私のコードは以下です: - 私は私の現在のディレクトリに存在しているテンプレートフォルダ内profile.ejsファイルを作成していると私は127.0.0.1/入力したときに私がすることを望む
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 ....");
4242/profile/anyname そのプロファイルページをレンダリングして表示する必要があります。
私Profile.ejsページは次のとおりです。
<!DOCTYPE html>
<html>
<head>
<title>Profile</title>
</head>
<body>
<h1>Welcome to the Profile !!</h1>
</body>
</html>
私は別の場所に正確な答えを見つけることができません。
Thaankますので洙多くを試してみてください! それは本当に私のために働いた:) – Pranshu