๐ ๊ณต๋ถํ๋ ์ง์ง์ํ์นด๋ ์ฒ์์ด์ง?
๋ฐฑ์๋ express์ node.js ์ฌ์ฉํ๊ธฐ (2) ๋ณธ๋ฌธ
๐ฉ๐ป ๋ฐฑ์๋(Back-End)/Node js
๋ฐฑ์๋ express์ node.js ์ฌ์ฉํ๊ธฐ (2)
์ง์ง์ํ์นด 2023. 1. 20. 15:07728x90
๋ฐ์ํ
<๋ณธ ๋ธ๋ก๊ทธ๋ ์ฐ๋ฆฌ๋ฐ ๋์ [Node.js] ๋ฐฑ์๋ ๋ง๋ณด๊ธฐ๋ฅผ ์ฐธ๊ณ ํด์ ๊ณต๋ถํ๋ฉฐ ์์ฑํ์์ต๋๋ค>
https://www.youtube.com/watch?v=7gF09WFGK4I&list=PLSK4WsJ8JS4cQ-niGNum4bkK_THHOizTs&index=4
โญ http๋ก ์๋ฒ ๊ฐ๋
const http = require("http");
const app = http.createServer((req, res) => {
console.log(req.url);
});
app.listen(3001, () => {
console.log("http๋ก ๊ฐ๋๋ ์๋ฒ")
})
โญ if ๋ฌธ์ผ๋ก ์๋ฒ ์ ์ด (ํ๊ธ ๊นจ์ง)
const http = require("http");
const app = http.createServer((req, res) => {
if (req.url === "/") {
res.end("์ฌ๊ธฐ๋ ๋ฃจํธ");
} else if (res.url === "/login") {
res.end("์ฌ๊ธฐ๋ ๋ก๊ทธ์ธ");
}
});
app.listen(3001, () => {
console.log("http๋ก ๊ฐ๋๋ ์๋ฒ")
})
โญ if ๋ฌธ์ผ๋ก ์๋ฒ ์ ์ด (ํ๊ธ ๊ฐ๋ฅ)
writeHead ์ฌ์ฉ
const http = require("http");
const app = http.createServer((req, res) => {
// ํ๊ธ๋ก ์ฝ์ด์ค
res.writeHead(200, {"Content-Type" : "text/html; charset=utf-8" });
if (req.url === "/") {
res.end("์ฌ๊ธฐ๋ ๋ฃจํธ");
} else if (req.url === "/login") {
res.end("์ฌ๊ธฐ๋ ๋ก๊ทธ์ธ");
}
});
app.listen(3001, () => {
console.log("http๋ก ๊ฐ๋๋ ์๋ฒ")
})
728x90
๋ฐ์ํ
'๐ฉโ๐ป ๋ฐฑ์๋(Back-End) > Node js' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐฑ์๋ express์ node.js ์ฌ์ฉํ๊ธฐ + Router (4) (0) | 2023.01.20 |
---|---|
๋ฐฑ์๋ express์ node.js ์ฌ์ฉํ๊ธฐ (3) (0) | 2023.01.20 |
๋ฐฑ์๋ express์ node.js ์ฌ์ฉํ๊ธฐ (1) (0) | 2023.01.20 |
๋ค์ ๋์ .. Flask-SocketIO ์ฌ์ฉํด์ live-graph ๋ง๋ค๊ธฐ (8) (1) | 2022.12.02 |
๋ค์ ๋์ .. Flask POST ์ฌ์ฉํด๋ณด๊ธฐ (7) (0) | 2022.12.01 |
Comments