๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ 132

[JavaScript] WebSocket vs Socket IO

Socket IO ์‹ค์‹œ๊ฐ„, ์–‘๋ฐฉํ–ฅ, event ๊ธฐ๋ฐ˜์˜ ํ†ต์‹ ์„ ํ•˜๋Š” framework webSocket์€ ์œ„์˜ ํ†ต์‹ ์„ ์ œ๊ณตํ•˜๋Š” ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜ Socket IO๋Š” webSocket์˜ ๋ถ€๊ฐ€๊ธฐ๋Šฅ (X) Socket IO๋Š” ๊ฐ€๋” webSocket์„ ์ด์šฉ (O) ๋งŒ์•ฝ webSocket ์ด์šฉ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋ฉด, Socket IO๋Š” ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์ด์šฉํ•ด์„œ ๊ณ„์† ์ž‘๋™ ์ž๋™ ์žฌ์—ฐ๊ฒฐ ์ง€์›, ์—ฐ๊ฒฐ ๋Š๊น€ ํ™•์ธ, ๋ฐ”์ด๋„ˆ๋ฆฌ ์ง€์› ํƒ„๋ ฅ์„ฑ, ์‹ ๋ขฐ์„ฑ 1. get socket server WebSocket //server.js const httpServer = http.createServer(app); const wsServer = new ws. WebSocketServer({httpServer}); Socket IO ์œ ์ €์—๊ฒŒ URL ์ œ๊ณต..

JavaScript 2024.03.29

[JavaScript] WebSocket | ์„œ๋ฒ„์™€ ๋ธŒ๋ผ์šฐ์ € ์—ฐ๊ฒฐ

1. express ๋กœ ์„œ๋ฒ„ ๊ตฌ์ถ• express ? node.js์˜ ํ”„๋ ˆ์ž„์›Œํฌ ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ํ”„๋ ˆ์ž„์›Œํฌ๋กœ Node.js์˜ API๋ฅผ ๋‹จ์ˆœํ™”ํ•˜๊ณ , ์‰ฝ๊ฒŒ ์„œ๋ฒ„ ๊ตฌ์ถ• ๊ฐ€๋Šฅ express application์œผ๋กœ๋ถ€ํ„ฐ http server ์ƒ์„ฑ import express from 'express'; import http from 'http'; const app = express(); const server = http.createServer(app); 2. http ์„œ๋ฒ„ ์œ„์—, webSocket ์„œ๋ฒ„ ๊ตฌ์ถ• -> ๊ฐ™์€ ํฌํŠธ ์ด์šฉ import ws from 'ws'; //http ์„œ๋ฒ„ ์ „๋‹ฌ const wss = new we.WebSocketServer({ server }); 3. WebSocket Connection :..

JavaScript 2024.03.28

[JavaScript] NodeJS, nodemon, babel | ํ”„๋กœ์ ํŠธ Server Setup

1. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ -> VSCode ๋กœ ์‹คํ–‰ $ mkdir prjname $ cd prjname $ npm init -y $ code . 2. git ์„ค์ • $ git init . $ git remote add origin gitURL $ git push -u origin main 3. ๊ธฐ๋ณธ ํŒŒ์ผ ์ƒ์„ฑ $ touch README.md $ touch .gitignore 4. nodemon ์„ค์ • $ npm i nodemon -D // nodemon.json { "exec" : "babel-node src/server.js" } 5. babel ์„ค์ • $ npm i @babel/core @babel/cli @babel/node @babel/preset-env -D { "presets" : ["@babel/pre..

JavaScript 2024.03.27

๋ธ”๋กœ๊ทธ ์ด์ „ ๊ด€๋ จ, ์ž๋ฃŒ ์กฐ์‚ฌ

Jekyll 2008 release Ruby๋กœ ์ž‘์„ฑ๋œ ์ •์  ์‚ฌ์ดํŠธ ์ƒ์„ฑ๊ธฐ(SSG, Static Site Generator) JavaScript๊ฐ€ ์‹คํ–‰๋˜๋ฉด ๋นˆ HTML ํŽ˜์ด์ง€ ์•ˆ์— ๋งˆํฌ์—…์„ ์ถ”๊ฐ€ํ•ด์ฃผ๋Š” SPA(Single Page Application)์™€ ๋‹ค๋ฅด๊ฒŒ, ๊ฐœ๋ฐœ ํ›„ Build ๊ณผ์ •์—์„œ ๋งˆํฌ์—… ์ƒ์„ฑ -> ๊ฒ€์ƒ‰ ์—”์ง„ ์ตœ์ ํ™”(SEO) Github Pages์—์„œ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ง€์›ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์— ์˜ฌ๋ฆฌ๋ฉด ์ž๋™์œผ๋กœ ์›น ํŽ˜์ด์ง€ ํ˜ธ์ŠคํŒ… ํ…œํ”Œ๋ฆฟ ์—”์ง„๊ณผ ๋‚ด๋ถ€ ๋ฐ์ดํ„ฐ ์ฟผ๋ฆฌ๋Š” Liquid ์–ธ์–ด ์‚ฌ์šฉ Gatsby 2015 release JAM Stack(JavaScript, API, Markup) ์›น ๊ตฌ์„ฑ ๋ฐฉ๋ฒ• JAM Stack ๋™์ž‘ ์›๋ฆฌ ๊ธฐ์กด : ์„œ๋ฒ„์˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋˜๋Š” CMS(Content Management S..

etc 2024.03.27

[Deploy] ์›น ์‚ฌ์ดํŠธ ๋ฐฐํฌ ํ”Œ๋žซํผ

๊ณผ๊ฑฐ ์›น์‚ฌ์ดํŠธ ๋ฐฐํฌ ์ž‘์„ฑ๋œ ํ”„๋กœ๊ทธ๋žจ์„ ๋Œ๋ฆฌ๋Š” ์„œ๋ฒ„๋ฅผ ๋‘๊ณ , ์ง์ ‘ ํ•˜๋“œ์›จ์–ด๋‚˜ ์šด์˜์ฒด์ œ ๊ทธ์™ธ ๋ชจ๋“  ๋ถ€๋ถ„์„ ์ง์ ‘ ๊ด€๋ฆฌ Iaas (Infrastructure as a Service) AWS, Azure ๊ฐ™์€ ํด๋ผ์šฐ๋”ฉ ์ปดํ“จํŒ… ์„œ๋น„์Šค ๋“ฑ์žฅ ์„œ๋ฒ„ ์ธํ”„๋ผ๋“ค์„ ๊ณต๊ธ‰ ์—…์ฒด์—์„œ ๊ด€๋ฆฌํ•˜๊ณ , ์‚ฌ์šฉ์ž๋Š” ์‰ฝ๊ฒŒ ์›น ๋ฐฐํฌ ๊ฐ€๋Šฅ ์„œ๋ฒ„ ์ธํ”„๋ผ๋ฅผ ๊ตฌ์„ฑํ•˜๊ณ  ์›น์„ ๋ฐฐํฌํ•˜๋ฉด 24์‹œ๊ฐ„ ์ฝ”๋“œ ๊ตฌ๋™ Faas (Functions as a Service) AWS lambda๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜๋Š” ํ”Œ๋žซํผ ์„œ๋ฒ„๋ฆฌ์Šค : ์œ„์˜ IaaS์ฒ˜๋Ÿผ ์„œ๋ฒ„๋ฅผ ๊ด€๋ฆฌํ•  ํ•„์š”๋„ ์—†์ด ํด๋ผ์šฐ๋“œ ์ œ๊ณต์—…์ฒด์— ๋ฆฌ์†Œ์Šค(ํ”„๋กœ๊ทธ๋žจ)๋งŒ ํ• ๋‹นํ•˜๋ฉด, ๋ฐ”๋กœ ํ”„๋กœ๋•์…˜ ํ™˜๊ฒฝ์œผ๋กœ ๋ฐฐํฌ e.g. Netlify, Vercel ํ”„๋กœ์ ํŠธ๋ฅผ ์—ฌ๋Ÿฌ๊ฐœ์˜ ํ•จ์ˆ˜๋กœ ์ชผ๊ฐœ์„œ -> ๋งค์šฐ ๊ฑฐ๋Œ€ํ•˜๊ณ  ๋ถ„์‚ฐ๋œ ์ปดํ“จํŒ… ์ž์›์— ํ•จ์ˆ˜๋ฅผ ๋“ฑ๋ก..

TIL 2024.03.22

[React] Promise.all() , Suspense | ์—ฌ๋Ÿฌ ๋น„๋™๊ธฐ ํ•จ์ˆ˜ ์ตœ์ ํ™”

๊ธฐ์กด ์ฝ”๋“œ ๋น„๋™๊ธฐ์ ์œผ๋กœ getMovie ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰๋˜๊ณ  ์™„๋ฃŒ ํ›„, getVideo ํ•จ์ˆ˜ ์‹คํ–‰ => ๋ฐ์ดํ„ฐ ์–‘์ด ๋งŽ์„ ๊ฒฝ์šฐ ๋น„ํšจ์œจ์  async function getMovie(id: string) { const response = await fetch(`${API_URL}/${id}`); return response.json(); } async function getVideos(id: string) { const response = await fetch(`${API_URL}/${id}/videos`); return response.json(); } //dynamic route export default async function MovieDetail({ params: { id } }: { params: {..

React 2024.03.20

[Next.js] fetch data, React vs Next.js

client component์—์„œ ๊ธฐ์กด์˜ API์™€ ์†Œํ†ตํ•˜๋˜ ๋ฐฉ์‹ useEffect useState -> metadata ์‚ฌ์šฉ ๋ถˆ๊ฐ€ ๋กœ๋”ฉ state ๊ตฌํ˜„ 'use client'; import { useEffect, useState } from 'react'; /* useState์˜ ์‚ฌ์šฉ์œผ๋กœ ์ธํ•ด, ์‚ฌ์šฉ ๋ถˆ๊ฐ€๋Šฅ export const metadata = { title: 'Home', }; */ export default function Page() { const [isLoading, setIsLoading] = useState(true); const [movies, setMovies] = useState([]); //useState -> interactive component๋ฅผ ์‚ฌ์šฉํ•˜๊ฒ ๋‹ค. -> "use c..

Next.js 2024.03.19

[Next.js] Server component vs Client component

์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ vs ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ ์ฒ˜์Œ ๋ฐฑ์—”๋“œ ์„œ๋ฒ„์—์„œ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์™€ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ชจ๋‘ ๋ Œ๋”๋ง ํด๋ผ์ธํŠธ ์ปดํฌ๋„ŒํŠธ๋งŒ ํ”„๋ก ํŠธ์—”๋“œ์—์„œ ๋‹ค์‹œ ๋ Œ๋”๋ง, ๋‹ค์‹œ hydrated(activate) ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ๋‹ค์šด๋กœ๋“œํ•˜์—ฌ ์‹คํ–‰ํ•˜๊ณ , ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ์˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ๋‹ค์šด๋กœ๋“œ X ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋Š” ๋”ฑ ํ•œ๋ฒˆ๋งŒ ์„œ๋ฒ„์— ์˜ํ•ด ์‹คํ–‰ -> ์œ ์ €๋Š” HTML ์–ป์Œ ๊ทธ ๋‹ค์Œ, ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ hydrate -> ์ƒํ˜ธ์ž‘์šฉ ๊ฐ€๋Šฅ ๋ชจ๋“  ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ ์ถ”๊ฐ€, useState, API, ์ง€๋ฆฌ ์ •๋ณด..etc ์›ํ•˜๋Š” ๊ฒฝ์šฐ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ ๋‚ด์— ํฌํ•จ ๊ฐ€๋Šฅ (๋ฐ˜๋Œ€์˜ ๊ฒฝ์šฐ X) "use client"๋ฅผ ์“ฐ์ง€ ์•Š์œผ๋ฉด, ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ชจ๋‘ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ์ด๋‹ค.

Next.js 2024.03.19

[git] ์—ฐ๊ด€ ์—†๋Š” ์ปค๋ฐ‹ ๋ณ‘ํ•ฉ ์˜ค๋ฅ˜ | fatal: refusing to merge unrelated histories

๋ฌธ์ œ ์ƒํ™ฉ ๋กœ์ปฌ์— ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ git init + init commit ๊นƒํ—ˆ๋ธŒ์—์„œ ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ ์ƒ์„ฑ + readme initial commit ๋‘ ๊ฐœ์˜ ์„œ๋กœ ๋‹ค๋ฅธ ์‹œ์ž‘์  commit์œผ๋กœ ๋จธ์ง€ ๋ถˆ๊ฐ€๋Šฅ ์—๋Ÿฌ ๋ฉ”์„ธ์ง€ fatal : refusing to merge unrelated histories. ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• ์„œ๋กœ ๊ด€๋ จ ์—†๋Š” ์ปค๋ฐ‹์˜ ๋จธ์ง€ ํ—ˆ์šฉ ๋ช…๋ น์–ด ์ ์šฉ --allow-unrelated-histories ex.) ๋จธ์ง€ ์ปค๋ฐ‹ i ) vim edit mode ๋ฉ”์„ธ์ง€ ์ž‘์„ฑ esc ) to quit input mode :wq ) save(wrote) and quiet ํ•ด๊ฒฐ ์™„๋ฃŒ ์ฐธ๊ณ  https://gdtbgl93.tistory.com/63 Git push๊ฐ€ ์•ˆ๋˜๋Š” ๊ฒฝ์šฐ (fatal: refusing to merge ..

Error-log 2024.03.18

[Next.js] Library vs Framework

Library (ex. React) ์ฝ”๋“œ ๋‚ด์—์„œ ์œ ์ €์˜ ํ•„์š”์— ์˜ํ•ด ์ด์šฉ, ํ™œ์šฉํ•˜๋Š” ๊ฒƒ ex. ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ..etc => ๊ตฌ์กฐ์— ๊ด€ํ•œ ๋ชจ๋“  ๊ฒฐ์ •์€ ์œ ์ €๊ฐ€ ๋‚ด๋ฆฐ๋‹ค. React : UI ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ build ํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ Framework (ex. Next.js) ํ”„๋ ˆ์ž„์›Œํฌ๊ฐ€ ๋‚˜์˜ ์ฝ”๋“œ๋ฅผ ํ™œ์šฉํ•œ๋‹ค => ์œ ์ €์˜ ์ฃผ๋„๊ถŒ X ์—ฌ๋Ÿฌ ๊ฒฐ์ •์„ ์œ ์ € ๋Œ€์‹ ํ•ด์ฃผ๊ณ , ์ž๋™ํ™” ์‹œํ‚จ๋‹ค ์œ ์ €๊ฐ€ ํ”„๋ ˆ์ž„์›Œํฌ์˜ ๊ทœ์น™์„ ์ง€์ผœ์•ผํ•œ๋‹ค.

Next.js 2024.03.15