0

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}`) })

5th Sep 2022, 5:37 PM
Abhi
1 Respuesta
0
works for me, what http request are you sending?
5th Sep 2022, 8:02 PM
Schindlabua
Schindlabua - avatar