WEB/NodeJS
[Node.js] Express 서버 구축
다콩잉
2022. 9. 18. 14:02
앞 글에서 환경설정한대로 실행할 때는 터미널에 npm run dev 입력
index.js
import express from "express";
const PORT = 4000; // 서버 포트 번호
const app = express();
// GET 요청을 통해 설정한 url 입력 및 메시지를 출력
// get('url 주소', request, response 인자를 가지는 콜백 함수) 형태
app.get("/", (req, res) => res.send("하잉")); //라우터에 대한 요청에 "하잉"으로 응답
const handelListening = () =>
console.log("서버 시작 " + `http://localhost:${PORT}`);
app.listen(PORT, handelListening); // app.listen() 함수를 사용하여 서버 실행
728x90