I am trying to get big size text through input field. when I try to console the chunks of data as buffer. I get only first chunk of the buffer. I can not understand what I am missing.
const http = require('http');
const server = http.createServer((req, res) => {
if (req.url === '/') {
res.write('<html><head><title>Form</title></head>');
res.write(
'<body><form method="post" action="/process"><input name="message" /></form></body>'
);
res.end();
} else if (req.url === '/process' && req.method === 'POST') {
req.on('data', (chunk) => {
console.log(chunk);
});
res.write('Thank you for submitting');
res.end();
} else {
res.write('Not found');
res.end();
}
});
server.listen(3000);
console.log('listening on port 3000');
You have to wait for the end event before sending back your response:
req.on('data', (chunk) => {
console.log(chunk);
});
req.on('end', () => {
res.write('Thank you for submitting');
res.end();
});