내일배움캠프 노드 4기/Today I Learned

express [Error: Cannot find module 'html']

Milb 2022. 12. 22. 21:19

문제 : html 모듈이 없다.

해결 : ejs 모듈 설치

npm install ejs

아래의 코드를 app.js에 추가해 주었다.

app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');

html 파일이 잘 불러와 지는지 보자

app.get("/", (req, res) => {
    res.render('index');
});

된것같다

index.html 코드

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Milb's Blog</title>
</head>

<body>
    <input placeholder="NickName"></br>
    <input placeholder="PassWord"></br>
    <button>로그인</button>
    <button>회원가입</button>
</body>

</html>

후기 : 전에 프로젝트 진행할 때는 jinja2라는 탬플릿 엔진을 썼는데 이것도 그런건가 싶다.