JavaScript
-
[Node.js] blogger-demo파일 리팩토링 | RefactoringJavaScript 2024. 1. 9. 15:07
https://github.com/heeheehoho/DevCourse GitHub - heeheehoho/DevCourse: Programmers Web Full-Stack Programmers Web Full-Stack. Contribute to heeheehoho/DevCourse development by creating an account on GitHub. github.com ✍🏻리팩토링(Refactoring) - 작성한 소스코드에서 소프트웨어의 외부 동작을 변경하지 않으면서 내부 구조를 개선하는 프로세스. - 이는 코드의 가독성을 높이고, 유지보수를 용이하게 하며, 오류를 찾고 성능을 개선하는 데 도움이 됨. - 리팩토링은 주로 코드의 명확성, 효율성, 간결성을 향상시키는데 목적을 둠. 리팩..
-
[Node.js] JSON 직렬화와 Map 객체JavaScript 2024. 1. 8. 22:12
https://github.com/heeheehoho/DevCourse/blob/main/backend/NodeBase/demo-api/blogger-demo.js app.get("/bloggers", function (req, res) { res.json(db); }); res.json(db)로 하면 안되는 이유? - "db"가 Map 객체이기 때문. Express의 res.json() 메소드는 JavaScript 객체나 배열을 JSON 형식의 문자열로 변환하여 클라이언트에게 응답으로 보내는데, Map 객체는 기본적으로 JSON으로 직렬화(Serialization)되지 않음. JSON 직렬화와 Map 객체 - 직렬화 불가: JavaScript의 Map 객체는 키-값 쌍을 저장하는 구조이다. 하지만, 이..
-
[Node.js]Express.js 기반 웹 서버 구축 연습 | REST APIJavaScript 2023. 12. 25. 00:04
https://github.com/heeheehoho/DevCourse GitHub - heeheehoho/DevCourse: Programmers Web Full-Stack Programmers Web Full-Stack. Contribute to heeheehoho/DevCourse development by creating an account on GitHub. github.com const express = require('express') //express 모듈 임포트 const app = express() // 함수 호출, 새로운 Express 애플리케이션 인스턴스 생성 app.get('/', function (req, res) { //루트 URL ('/')에 대한 GET 요청을 처리하는 핸들..
-
[TIL] 2023.12.16 | 웹 풀사이클 데브코스JavaScript 2023. 12. 17. 22:03
✔️Facts - 프로그래머스 웹 풀사이클 데브코스 수업 - tistory 글 작성 💡Findings - 최근에는 parse() 함수를 사용하지 않고, URL 클래스를 사용하는 것이 권장된다. URL 클래스는 WHATWG URL 표준을 따르며, URL을 해석하고 조작하는 데 더 현대적이고 강력한 방법을 제공한다. - favicon.ico error 해결 방법 https://jungheeho.tistory.com/53 [Node.js] URL 파싱(parsing) [복습] - Node.js의 http 모듈을 사용하여 기본적인 웹 서버를 만드는 예시 코드 const http = require('http'); // 서버 생성 const server = http.createServer((req, res) => ..
-
[Node.js] Url에 따라 프론트엔드에 다른 response 보내기 | new URLJavaScript 2023. 12. 17. 17:04
[이전 게시물] https://jungheeho.tistory.com/54 [Node.js] URL parsing | TypeError: handle[pathname] is not a function ⚠️ TypeError: handle[pathname] is not a function https://github.com/heeheehoho/DevCourse/tree/main/backend/URLWeberver TypeError: handle[pathname] is not a function at route (/Users/jungheeho/Desktop/programmers/DevCourse/backend/URLWeberver/router.js: jungheeho.tistory.com 💻 전체 코드 이전 ..
-
[Node.js] URL parsing | TypeError: handle[pathname] is not a function | favicon.ico에러JavaScript 2023. 12. 17. 10:40
⚠️ TypeError: handle[pathname] is not a function https://github.com/heeheehoho/DevCourse/tree/main/backend/URLWeberver TypeError: handle[pathname] is not a function at route (/Users/jungheeho/Desktop/programmers/DevCourse/backend/URLWeberver/router.js:4:21) at Server.onRequest (/Users/jungheeho/Desktop/programmers/DevCourse/backend/URLWeberver/server.js:7:9) at Server.emit (node:events:513:28) a..
-
[Node.js] URL 파싱(parsing)JavaScript 2023. 12. 17. 02:08
[복습] - Node.js의 http 모듈을 사용하여 기본적인 웹 서버를 만드는 예시 코드 const http = require('http'); // 서버 생성 const server = http.createServer((req, res) => { // 응답 헤더 설정 res.writeHead(200, {'Content-Type': 'text/plain'}); // 응답 본문 보내기 res.end('Hello, World!\n'); }); // 서버가 3000 포트에서 수신을 시작 server.listen(3000, () => { console.log('Server running at http://localhost:3000/'); }); ✔️URL 파싱 1. 경로 기반 라우팅 (Path-Based Rou..
-
[Node.js] 웹서버 구축하기, 서버 모듈화 | http basicJavaScript 2023. 12. 8. 22:25
1. node.js의 http 모듈을 사용해서 간단한 웹서버를 구축 - server.js const http = require('http'); // node.js가 가고 있는 require 함수로 ()안의 모듈 가져옴 const onRequest = (request, response) => { response.writeHead(200, {'Content-Type': 'text/html'}); response.end('Hello Node.js'); }; http.createServer(onRequest).listen(8888, () => { console.log('Server is running on http://localhost:8888'); }); 2. terminal에서 "node [파일명]"으로 서..