Server Request Respond #2 (Node JS, Express, NodeMon)

0_CyberLover_0·2022년 3월 18일
0

Node.JS # 01

목록 보기
10/21
post-thumbnail

이번에는 서버에게 get request에 어떻게 응답해야 되는지 알아보자.

지금 할일은 express application을 만들고 나서 진행해야 된다.

const app = express();

app.get("/", () => console.log("somebody is trying to go home."));

위 처럼 express application이 만들어진 다음부터 코드를 작성해야 된다.

위 코드에서 ( ) => 이해가 안되는 function이라 찾아 보았다.

(  = function  ( )  ===    = ( ) =>  )

express와 연관된 코드들이기 때문이다.

application을 만들고


const handleListening = () =>

console.log(`✅ Server listening on port http://localhost:${PORT} 🚀`);

app.listen(PORT, handleListening);

윗 부분에서 외부 접속을 listen하고 application 설정을 해놓은 상태라면 그거에 따라서

작동을 한다음 외부에 open 되는 원리이다.



현재 저 상태는 계속 기다리기만 하는 상태이다.

서버에 기다리라고만 해놓은 상태라서 브라우저는 계속 기다리고 있다.

(console 안에서는 잘 작동 되고 있다.이렇게 뜨고 있으니 잘 되고 있는거다.
[nodemon] restarting due to changes...
[nodemon] starting `babel-node src/server.js`
✅ Server listening on port http://localhost:4000 🚀
somebody is trying to go home.)

무한 로딩상태인 것이다.

유저가 뭔가를 요청하거나, 보내거나, 어떤 행동을 한다.

(request)

profile
꿈꾸는 개발자

0개의 댓글