body-Parser2 [nodeJS] body-parser로 JSON 파싱하기 1. body-parser HTTP 요청의 본문(body)을 쉽게 파싱하도록 도와주는 미들웨어 req.body는 body-parser를 사용하기 전에는 디폴트 값으로 Undefined이 설정되서 그냥 사용 시 에러 발생 요청 데이터를 서버에서 처리하기 쉽도록 데이터 포맷 지원 JSON (application/json) URL-encoded (application/x-www-form-urlencoded) Raw (application/octet-stream) Text (text/plain) 2. 사용 방법 npm install body-parser const express = require('express'); const bodyParser = require('body-parser'); const app .. 2023. 6. 17. [nodeJS] 초보자도 쉽게 따라할 수 있는 nodeJS로 서버 만들기 1. Node.js 설치 Node.js 공식 웹사이트(https://nodejs.org/)에서 LTS 버전 설치 2. 프로젝트 생성 및요한 패키지 설치 프로젝트 폴더를 생성하고 터미널에 다음 명령어를 입력 // 프로젝트 초기화 npm init 웹과 API 서버를 구축할 수 있는 express 프레임워크와 HTTP 요청 본문(body)에 들어있는 데이터를 해석하고 처리하는 body-parser 미들웨어 설치 npm install express body-parser 3. 기본 서버 구축 프로젝트 폴더에 "app.js" 파일을 생성하고 다음 코드를 작성하여 서버를 생성 // 서버 만들기에 필요한 모듈 가져오기 const express = require("express"); const bodyParser = r.. 2023. 6. 8. 이전 1 다음