inflearn logo
강의

Khóa học

Chia sẻ kiến thức

Một trại huấn luyện phát triển toàn diện thực sự dành cho những người không chuyên ngành

Xây dựng máy chủ Grab Market

nodejs sever 질문

1246

JJARLIT

7 câu hỏi đã được viết

1

'그랩마켓서버구축하기' 강의에서 localhost:8080에 접속 후 /products로 진입하면 처음에는 렌더링 되지만 이후 터미널에서  events.js:292

      throw er; // Unhandled 'error' event

      ^

Error [ERR_STREAM_WRITE_AFTER_END]: write after end

    at writeAfterEnd (_http_outgoing.js:668:15)

    at ServerResponse.end (_http_outgoing.js:788:7)

    at Server.<anonymous> (C:\Users\JAEHA\Desktop\grab-market-server\index.js:24:7)

    at Server.emit (events.js:315:20)

    at parserOnIncoming (_http_server.js:874:12)

    at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17)

Emitted 'error' event on ServerResponse instance at:

    at writeAfterEndNT (_http_outgoing.js:727:7)

    at processTicksAndRejections (internal/process/task_queues.js:81:21) {

  code: 'ERR_STREAM_WRITE_AFTER_END'

}

이런 에러가 뜨면서 서버가 다운됩니다. 구글링해서 해봤는데도 효과가 없습니다.. vscode도 종료했다 켰어요!

tensorflow react-native javascript react 머신러닝 배워볼래요? nodejs express HTML/CSS

Câu trả lời 6

4

grab

다행이네요! Window 환경에서 가끔씩 동작이 다를 때가 있어 저도 수업자료에 넣어두겠습니다.

감사합니다 😁

3

grab

var http = require("http");
var hostname = "127.0.0.1";
var port = 8080;

const server = http.createServer(function (req, res) {
  const path = req.url;
  const method = req.method;
  if (path === "/products") {
    if (method === "GET") {
      res.writeHead(200, { "Content-Type": "application/json" });
      const products = JSON.stringify([
        {
          name: "농구공",
          price: 5000,
        },
      ]);
      res.end(products);
    } else if (method === "POST") {
      res.end("생성되었습니다!");
    }
  }else{
    res.end("Good Bye");
} }); server.listen(port, hostname); console.log("grab market server on!");

위와 같이 코드 변경해보시겠어요?
바꾼 부분은 else를 추가했습니다.

if(path == '/products'){

  ...

} else{

  res.end("Good Bye");

}

1

JJARLIT

해결됐습니다!! 더 찾아보고 고민했어야됐는데... 이렇게 간단하다니 ... 감사합니다!

0

JJARLIT

index.js 입니다 참고로 깃허브에 올리신거 복사해서 해봤는데도 똑같은 오류가 났습니다 ㅠ

0

JJARLIT

var http = require("http");
var hostname = "127.0.0.1";
var port = 8080;

const server = http.createServer(function (req, res) {
  const path = req.url;
  const method = req.method;
  if (path === "/products") {
    if (method === "GET") {
      res.writeHead(200, { "Content-Type": "application/json" });
      const products = JSON.stringify([
        {
          name: "농구공",
          price: 5000,
        },
      ]);
      res.end(products);
    } else if (method === "POST") {
      res.end("생성되었습니다!");
    }
  }
  res.end("Good Bye");
});

server.listen(port, hostname);

console.log("grab market server on!");

0

grab

/products 라우터 전체 코드 올려주시면 빠르게 확인이 가능할 것 같아요~!
아니면 해당 소스코드 파일을 첨부로 올려주셔도 좋습니다.

[해결]그랩님 답변 주세요.

0

165

2

그랩님의 답변을 기다립니다/102강 전반적인 에러

0

144

2

[그랩님께]101강 안드로이드 에러들(Key prop)해결방법 궁금합니다.

0

126

2

[재질문][그랩님 답변 부탁드립니다]101강

0

143

2

[그랩님 답변 부탁드립니다]101강 Axios 에러와 502 Bad Gateway 질문

0

99

2

Ngrok 설치 후 forwarding Url 에러

0

134

2

[그랩님께,Ngrok 악성코드 인식 해결방법]질문 드립니다.

0

222

2

Ngrok 설치 후 forwarding Url로 연결 불가

0

138

1

그랩님,[꼭] 답변 부탁드립니다.

0

68

1

[꼭][[꼭] 그랩님, 답변 부탁드립니다], Failed to load resource: the server responded with a status of 404 (Not Found) 상품 상세 페이지 질문입니다.

0

155

1

6강/7강 수업

0

53

1

그랩님, 상품 상세 페이지 에러와 의문점 질문드립니다.

0

100

2

그랩님, 해결되지 않은 에러 메시지 [꼭] 답변 부탁 드립니다.

0

138

2

[재 질문]Cannot read properties of undefined (reading 'map') TypeError: Cannot read properties of undefined (reading 'map') 에러 해결 어떻게 하나요?

0

89

1

Cannot read properties of undefined (reading 'map') TypeError: Cannot read properties of undefined (reading 'map') 에러 해결 어떻게 하나요?

0

130

2

일반적인 css 꾸미기에서 width와 height의 값?

0

94

2

Windows에서의 업로드 후 홈화면 상품이미지 오류 해결방법

0

197

1

그랩마켓 웹화면 구현하기 -2 질문입니다.

0

121

1

react에 반영이 되지 않습니다.

0

243

1

터미널 npm install -g create-react-app 작성 후 오류

0

422

1

create-react-app my app 실행 시 에러

0

357

2

포스트맨 질문

0

100

1

<꼭 답변 부탁 드립니다>그랩선생님, [컴포넌트 사용하기] 강의에서 질문 있습니다.

0

261

2

그랩선생님, 질문 답변 부탁 드립니다.vscode에서 npm install -g create-react-app 입력 후 에러 입니다.

0

483

2