Created
March 2, 2019 20:26
-
-
Save shuhei/58a488753731554f8e52cd3fd7643e5a to your computer and use it in GitHub Desktop.
Callback of ClientRequest.prototype.end
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const server = http.createServer((req, res) => { | |
console.log('[server] request'); | |
setTimeout(() => { | |
res.end('hello'); | |
console.log('[server] response'); | |
}, 3000); | |
}); | |
server.listen(3000, () => { | |
startClient(); | |
}); | |
function startClient() { | |
const req = http.request({ | |
hostname: '127.0.0.1', | |
port: 3000, | |
}); | |
req.on('response', (res) => { | |
console.log('[client] response'); | |
res.on('end', () => { | |
console.log('[client] response end'); | |
}); | |
res.resume(); | |
server.close(() => { | |
console.log('[client] server close'); | |
}); | |
}); | |
req.end(() => { | |
console.log('[client] request finish'); | |
}); | |
console.log('[client] request start'); | |
} |
Author
shuhei
commented
Mar 2, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment