404 오류페이지
무작위의 주소를 입력하면 일반적으로 404error페이지가 나타난다. app.js 파일로 돌아가서 미들웨어나 또하는 express가 미들웨어를 사용해서 요청을 처리해주면 된다.
<app.js>
// (/)로 처리해줘도 되지만 아래 값이 default이기 때문에 생략해도 된다.
app.use(/);
//get요청 뿐만아니라 모든 http의 요청을 처리한다. use를 사용했으니
app.use((req, res, next) => {
res.status.send('<h1>Page not found</h1>');
});
→ res.send 로 404 status 코드를 설정할 수 도 있다. send 이전에 status라는 method를 연결해준다.
다른 파일들에서도 사용이 가능하다. 전송전에 항상 status나 setHeader를 호출 할 수 있다. 모든 method 호출을 연계할 수 있고 마지막이 send기만 하면 된다.
그리고 status(404)를 해준다. 보통 페이지를 찾을 수 없는 경우의 일반적인 코드이다.

Express Router의 또 다른기능
<admin.js>
router.get('/admin/add-product', (req, res, next) => {
res.send(
'<form action="/product" method="POST"><input type="text" name="title"><button type="submit">Add Product</button></form>'
);
});
router.post('admin/add-product', (req, res, next) => {
console.log(req.body);
res.redirect('/');
});
method가 get과 post로 다르기 때문에 경로를 반복해도 된다. 따라서 위의 둘은 서로 다른 route가 된다.
그런데 /admin의 경로를
<app.js>
에서 '/admin'을 추가해주면, /admin으로 시작하는 라우트만 adminRoute파일로 들어가게된다.
app.use('/admin', adminRoutes);
app.use(shopRoutes);
이제 /add-product는 /admin/add-product route에 매칭된다. /admin이 생략되었으니까.

/admin/add-product 경로로 가면 폼을 확인할 수 있다. 하지만 book를 입력하고 넘어가면 /add-product가 나오기에 또다시 404페이지에 도달한다.
<admin.js>에서 작성했던 폼에 /admin을 넣어 수정해주어야한다.
router.get('/add-product', (req, res, next) => {
res.send(
'<form action="/admin/add-product" method="POST"><input type="text" name="title"><button type="submit">Add Product</button></form>'
);
});
Error 발생 그리고 허무한 해결..
노드몬을 실행하려는데 오류가 떴다.

npm audit fix를 설치하래서 했는데도 되지않았다.
그래서
npm cache clean --force
npm install --cache
를 깔았는데.. 왜 안돼는지 알았다. npm run dev 명령어가 아니라 package.json에 내가 start를 nodemon app.js로 해놨었다. 그냥 npm start를 하면 됐었음을..
