server 3

[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

[Next.js] Server component vs Client component

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

Next.js 2024.03.19

[Next.js] CSR(client side render) vs SSR(server side render)

* Rendering : js code๋ฅผ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋Š” html๋กœ ๋ฐ”๊พธ๋Š” ๊ฒƒ - React render : CSR (client side rendering) create-react-app ์„ ์‚ฌ์šฉํ•ด react๋งŒ์œผ๋กœ application์„ ์ƒ์„ฑํ•˜๋ฉด , client side rendering client side rendering => ์‚ฌ์šฉ์ž ๋ธŒ๋ผ์šฐ์ €์ธ client๋‹จ์—์„œ rendering ์ž‘์—…์„ ํ•œ๋‹ค. ๋‹จ์  ํŽ˜์ด์ง€์˜ ์‹ค์ œ ์†Œ์Šค์ฝ”๋“œ๋Š” ๋น„์–ด์žˆ๋‹ค. ex. = UI๊ฐ€ ์—†๋‹ค ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ๋ชจ๋“  JS ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ , ์‹คํ–‰ํ•œ ํ›„์—์•ผ ํ™”๋ฉด์— ๋ณด์—ฌ์ง€๋Š” ๊ฒƒ ์ƒˆ๋กœ๊ณ ์นจ ์‹œ, JS์—”์ง„์ด ์œ„์˜ ์‚ฌํ•ญ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์‹œ๊ฐ„ ๋™์•ˆ ๋นˆ ํ™”๋ฉด์ด ๋ณด์—ฌ์ง SEO, ๊ฒ€์ƒ‰ ์—”์ง„ ์ตœ์ ํ™” Search Engine Optimization Goo..

Next.js 2024.03.15