NodeJS에서 가장 먼저 시도한 것으로, 방문자에게 IP 주소를 알려주는 HTML 페이지를 표시하는 간단한 앱을 작성하고 있습니다.TypeError : Express에서 JS를 사용하려고 할 때 this.engine이 함수가 아닙니다.
TypeError: this.engine is not a function
at View.render (/Users/macuser/NodeJS/hello/node_modules/express/lib/view.js:126:8)
at tryRender (/Users/macuser/NodeJS/hello/node_modules/express/lib/application.js:639:10)
at EventEmitter.render (/Users/macuser/NodeJS/hello/node_modules/express/lib/application.js:591:3)
at ServerResponse.render (/Users/macuser/NodeJS/hello/node_modules/express/lib/response.js:960:7)
at /Users/macuser/NodeJS/hello/index.js:8:9
at Layer.handle [as handle_request] (/Users/macuser/NodeJS/hello/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/macuser/NodeJS/hello/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/Users/macuser/NodeJS/hello/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/macuser/NodeJS/hello/node_modules/express/lib/router/layer.js:95:5)
at /Users/macuser/NodeJS/hello/node_modules/express/lib/router/index.js:277:22
:
<!DOCTYPE html>
<html>
<head>
<title>Hello, World!</title>
</head>
<body>
<h1>Hello, World!</h1>
<hr>
<p>If you're reading this, the NodeJS setup is working. Check your developer console. See if there's any HTTP error in there.</p>
<p>Anyway, your IP address is {{ip}}</p>
</body>
</html>
그리고 여기에 내가 요청을 보낼 제가 콘솔의 모든 시간을 얻을 : 여기
여기 /views/frontPage.html
의 모습 방법
var express = require('express');
var app = express();
app.set('view engine', 'mu2');
app.get('/', function (req, res) {
res.setHeader('Content-Type', 'text/html'); // Do I have to do this? I'm not sure.
res.render('frontPage.html', {
ip: req.ip
});
res.send();
});
app.listen(8080, function() {
console.log("Listening on port 8080");
});
처럼 보이는 방법
views/
안에 이미 frontPage.html
을 설정하고 I a NPM (npm install mu2 --save
)의 콧수염을 이미 설치했습니다. 무엇이 문제입니까?
몇 가지 조사를 한 후 Express와 Mustache의 호환성에 대한 모순이 있음을 발견했습니다. 웹 사이트의 가이드가 호환성이 있다고하더라도, Mustache는이 목록에 없습니다. https://github.com/expressjs/express/wiki?_ga=1.74621138.1527575629.1480681917#template-engines – starleaf1