[node.js]res.send vs res.end 차이점

bible_k_·2023년 4월 9일
0

res.send의 특징

    app.get('/',(req,res)=>{
       res.send('<b>hello</b>');
    });

     app.get('/',(req,res)=>{
         res.send({msg:'hello'});
     });

  • output의 구조와 헤더 정보를 확인하고 그에 따라 Content-Type을 설정해준다.
  • 응답 헤더에 Etag 속성을 설정한다.
    *ETag HTTP응답 헤더는 리소스의 버전에 대한 식별자이다.

res.end의 특징

      app.get('/',(req,res)=>{
           res.end('<b>hello</b>');
      }); 

  • 응답 프로세스를 종료한다.
  • 데이터를 전송하지 않고 빠르게 응답을 종료할 때 사용할 수 있다.
  • res.send와 달리 text로 응답할 뿐 Content-Type을 설정해주지 않는다.
  • res와 달리 ETag 속성을 설정해주지 않는다.

References

https://stackoverflow.com/questions/29555290/what-is-the-difference-between-res-end-and-res-send
https://jos50275266.medium.com/what-is-the-difference-between-response-send-response-end-and-response-write-c0457dba3ce2

profile
후론트엔드 개발자

0개의 댓글