app.get("/edit/:id", function (요청, 응답) {
db.collection("post").findOne(
{ _id: parseInt(요청.params.id) },
function (에러, 결과) {
if (에러) {
console.log(에러);
응답.render("edit-error.ejs");
}
응답.render("edit.ejs", { post: 결과 });
}
);
});
위처럼 코드를 짜서 error 발견 시 edit-error.ejs페이지를 보여주고 싶었는데
/edit/(없는숫자) 로 이동하니까 edit.ejs에서 value에 넣을 값이 없다면서 에러화면으로 넘어가지 않습니다.ㅠㅠ
Cannot read property '제목' of null
뭔가, 앞에 db에 id값이 있는지 없는지 확인하는 if문이 필요한가 싶은데 어떻게 짜면 될까요?ㅠㅠ