프로젝트 복원
package.json을 바탕으로 필요한 라이브러리들을 한꺼번에 설치
package.json 파일 옮겨놓기 > npm install
express 모듈
use() : 미들웨어를 등록
resp.redirect() : 웹 페이지의 경로를 강제로 이동
req.query.키 : 클라이언트에서 GET 방식으로 전송한 요청 파라미터를 확인
req.body.키 : 클라이언트에서 POST 방식으로 전송한 요청 파라미터를 확인.
단, post 방식을 통한 요청 파라미터를 확인하려면 body-parser와 같은 모듈을 사용해야 한다.
포스트맨
https://www.postman.com/downloads/
Download Postman | Get Started for Free
Try Postman for free! Join 17 million developers who rely on Postman, the collaboration platform for API development. Create better APIs—faster.
www.postman.com
REST
Representational State Transfer
자원을 이름으로 구분하여 해당 자원의 상태를 주고 받는것을 의미
app.use(bp.urlencoded({extended:false}))
body-parser 미들웨어의 여러 옵션 중에 extended를 false로 설정하면 node.js에 기본으로 내장된 queryString 사용
true일 때 따로 설치가 필요한 npm qs 라이브러리를 사용
Router 미들웨어
사용자의 다양한 요청이 들어왔을 때 use() 메소드로 설정한 미들웨어가 항상 호출되는 불편한 점을 개선하여 만들어진 모듈이다.
Router 객체
const 객체명 = express.Router();
객체명.route('/요청URL').get(호출할 함수);
객체명.route('/요청URL').post(호출할 함수);
express에 Router 객체 등록
app.use('/',객체명);
템플릿 엔진
View를 구현하기 위한 템플릿을 의미한다.
EJS(Embedded JavaScript) 모듈
특정한 형식의 파일로부터 HTML 페이지를 생성하는 모듈
npm i ejs
'node.js' 카테고리의 다른 글
[node.js] 쿠키, 세션 (0) | 2022.02.21 |
---|---|
[node.js] Jade, 메일 보내기 (0) | 2022.02.21 |
[node.js] fs 모듈, http 모듈, express 모듈 (0) | 2022.02.21 |