![](https://velog.velcdn.com/images%2Fhackjoong%2Fpost%2F599d476b-7bab-45dd-b73e-250cfdab9b85%2F%EC%8A%A4%ED%81%AC%EB%A6%B0%EC%83%B7%2C%202022-03-21%2012-32-15.png)
ERR_STREAM_WRITE_AFTER_END
- 응답(res.end(...))을 두 번 이상 했을 때 발생하는 에러
Error Code
const http = require('http');
const server = http.createServer((request, response) => {
const { method, url } = request
if(method === 'POST' && url === '/lower') {
response.end('codestates')
}
else if(method === 'POST' && url === '/upper') {
response.end('CodeStates')
}
response.end('response')
});
수정
const http = require('http');
const server = http.createServer((request, response) => {
const { method, url } = request
if(method === 'POST' && url === '/lower') {
response.end('codestates')
}
else if(method === 'POST' && url === '/upper') {
response.end('CodeStates')
} else {
response.end('response')
}
});
server.listen(4000, () => {
console.log('서버 오픈')
})
- 마지막
response.end('response')
를 else
처리