The connection was rejected. 오류 해결

홍제섭·2023년 11월 14일
1
post-thumbnail

문제 상황 : rest client 공부 중, http 파일을 하나 생성하고 Send Request를 눌러 서버를 키려고했는데 하기와 같은 오류 발생

먼저 내 코드는

===========================

1 server 변수 설정

@server = http://localhost:3000

2 GET 요청 보내기

GET {{server}}/person

3 POST 요청 보내기

POST {{server}}/person
Content-Type: application/json

{
"name" : "jeseop",
"age" : 30,
"email" : "jeseop@backend.com"
}

4 생성한 문서 확인

GET {{server}}/person/jeseop@backend.com

5 Put 요청 보내기, 문서 수정하기

PUT {{server}}/person/jeseop@backend.com

{{
"age" : 31
}}

6 문서 삭제하기

DELETE {{server}}/person/jeseop@backend.com

=========================

오류 :
The connection was rejected. Either the requested service isn’t running on the requested server/port, the proxy settings in vscode are misconfigured, or a firewall is blocking requests. Details: RequestError: connect ECONNREFUSED 127.0.0.1:3000.

원인 : 일반적으로 해당 포트(여기서는 3000번 포트)에서 실행 중인 서비스가 없거나 연결이 거부되었을 때 발생. 나 같은 경우 express로 서버를 실행한 뒤, Send Request를 눌러야하는데 그 부분을 놓쳤음.

해결 방법 :
1. 해당 폴더에 express install (npm install express)
2. express 서버 실행 (내 경우 테스트할 express API Code 이름가 mogoose-crud.js였음.
node .\mongoose-crud.js)
3. Send Request 가능

profile
보여주고 증명하며 사는 삶.

0개의 댓글