에러
Error: template not found: index.html
at createTemplate (/home/cloudcoke/my/playground/router/node_modules/nunjucks/src/environment.js:290:15)
at next (/home/cloudcoke/my/playground/router/node_modules/nunjucks/src/lib.js:330:7)
at handle (/home/cloudcoke/my/playground/router/node_modules/nunjucks/src/environment.js:329:11)
at /home/cloudcoke/my/playground/router/node_modules/nunjucks/src/environment.js:339:9
at next (/home/cloudcoke/my/playground/router/node_modules/nunjucks/src/lib.js:328:7)
at Object.asyncIter (/home/cloudcoke/my/playground/router/node_modules/nunjucks/src/lib.js:334:3)
at Environment.getTemplate (/home/cloudcoke/my/playground/router/node_modules/nunjucks/src/environment.js:321:9)
at Environment.render (/home/cloudcoke/my/playground/router/node_modules/nunjucks/src/environment.js:360:10)
at NunjucksView.render (/home/cloudcoke/my/playground/router/node_modules/nunjucks/src/express-app.js:22:9)
at tryRender (/home/cloudcoke/my/playground/router/node_modules/express/lib/application.js:657:10)
원인
- index.html template을 찾을 수 없다는 에러
- html 파일을 views 디렉토리에 모아놓고 nunjucks 설정을 view 디렉토리를 바라보게 설정을 해준게 원인이었다.
app.set("view engine", "html");
nunjucks.configure("view", {
express: app,
});
app.get("/", (req, res) => {
res.render("index.html");
});
해결
- nunjucks 설정을 views 디렉토리를 바라보게 설정해주면 된다.
app.set("view engine", "html");
nunjucks.configure("views", {
express: app,
});
app.get("/", (req, res) => {
res.render("index.html");
});