프로그래밍 공부/백엔드
블로그 만들기: 챌린지 8 compose에 작성한 글이 콘솔로그로 출력
송혜이
2022. 3. 13. 19:17
728x90
1. compose.ejs
1-1 form의 action은 버튼을 누르면 어디로 submit 하느냐-> /compose과 연결하고, method를 post로 지정
1-2. input에 name 설정
1-3. button 타입은 submit이어야 버튼을 누르면 app.post로 전달됨
<%- include partials/header.ejs -%>
<h1>Compose</h1>
<form action="/compose" method ="post">
<input type="text" name="postTitle">
<button type="submit" name="button">Publish</button>
</form>
<%- include partials/footer.ejs -%>
2. app.js
app.post(' 페이지 지정' , 콜백함수)
app.post('/compose', function(req, res) {
console.log(req.body.postTitle);
})
req.body.postTitle
인풋된 입력물은 req.body.인풋의 이름 에 저장된다
req객체는 유저가 request한 정보(여기서는 텍스트 인풋을 요청)가 저장되어 있고-
이를 불러내려면, req.body.postTitle
- req.body : req한 정보를 body-Parser가 파싱하는 명령어/ body가 body-parser를 뜻하는지 html에 body 부분을 뜻하는지는 나도 모름...
- postTitle: input name- 인풋된 정보를 파싱 해주세요(파싱: 구문분석/ 즉 유저가 입력한 영어를 컴터언어로 분석해서 변경해주세요.~~~~라고 이해합니다. 야매 독학의 한계)
를 불러와야 한다.