반응형
JSON
-
Node로 JSON 주고받기 - CodeHan의 코딩공부BackEnd/개념정리 2022. 9. 11. 13:09
이번엔 Node로 .json파일을 주고 받아보자. 이것 역시 크게 어렵지 않다. request와 response만 이해했다면 바로 할 수 있다. const fs = require('fs'); const http = require('http'); const server = http.createServer((req,res) => { const url = req.url; const method = req.method; if(url === '/courses') { if(method === 'GET') { res.writeHead(200, {'Content-Type' : 'Application/json'}) res.end(JSON.stringify(course)) } else if(method === 'POST'..