π 곡λΆνλ μ§μ§μνμΉ΄λ μ²μμ΄μ§?
Typescript λ‘ express αα ₯α¨αα αΌαα ‘αα ΅ λ³Έλ¬Έ
π©π» λ°±μλ(Back-End)/Typescript
Typescript λ‘ express αα ₯α¨αα αΌαα ‘αα ΅
μ§μ§μνμΉ΄ 2023. 5. 31. 17:42728x90
λ°μν
<λ³Έ λΈλ‘κ·Έλ memi Dev μ μ νλΈλ₯Ό μ°Έκ³ ν΄μ 곡λΆνλ©° μμ±νμμ΅λλ€ :-)>
=> αα ¦αα ΅αα ΄ αα ’αα ‘α―αα ‘α¨αα 20 typescript express αα ₯α¨αα αΌαα ‘αα ΅
π§Έ http λ‘ μΉ μλ² κ΅¬ννκΈ°
import http from "node:http"
const server = http.createServer((req, res) => {
if (req.url === "/about") res.end("good!!")
else res.end("hello")
})
server.listen(3000)
π§Έ express λ‘ μΉ μλ² κ΅¬ννκΈ°
import express from "express"
const app = express()
app.get("/", (req, res) => {
res.send("hello")
})
app.get("/about", (req, res) => {
res.send("about")
})
app.listen(4000)
π§Έ Router λ‘ κ΅¬λΆνμ¬ express λ‘ μΉ μλ² κ΅¬ννκΈ°
π© index.ts
import express from "express"
import birds from "./routes/birds"
import dogs from "./routes/dogs"
const app = express()
app.use("/birds", birds)
app.use("/dogs", dogs)
app.listen(4000)
π© routes/birds.ts
import express from "express"
const router = express.Router()
router.get("/", (req, res) => {
res.send("birds!")
})
export default router
π© routes/dogs.ts
import express from "express"
const router = express.Router()
router.get("/", (req, res) => {
res.send("dogs!")
})
export default router
728x90
λ°μν
'π©βπ» λ°±μλ(Back-End) > Typescript' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Typescript λ‘ ννμ΄μ§ λ§λ€μ΄λ³΄κΈ° (2) | 2023.05.31 |
---|---|
Typescriptλ‘ express λ²μ μ html αα ©αα ’αα ΅ (0) | 2023.05.31 |
Typescript λ‘ socket μ¬μ©νκΈ° (server, client) (0) | 2023.05.29 |
TypeScript μ²μ μ¬μ©ν΄λ³΄κΈ° (μ€μΉνκΈ°, κΈ°λ³Έμ μΈ νμ λͺ λ Ή) (0) | 2023.05.20 |
Comments