New course! Every coder should learn Generative AI!
Try a free lesson0
Pls help me with this nodejs code
The message variable is not getting updated on sending request, why the req.on(data) method not working in the below code? var http = require('http'); const host = 'localhost' const port = 8000; const server = http.createServer((req, res) => { if (req.method === 'POST') { let message = '' req.on('data', (chunk) => { message += chunk; }) req.on('close', () => { console.log(message) }) req.on('end', () => { res.end(message); }) } else { res.end("Get reqest") } }) server.listen(port, host, () => { console.log(`Server running on ${host} on port ${port}`) })
1 Answer
0
works for me, what http request are you sending?