How to handle a POST request without unnecessary require's?

Want to handle a POST request using NodeJS and http module, how to do it without extra modules?
June 3rd 19 at 20:22
2 answers
June 3rd 19 at 20:24
Solution
Oh! I washed down the materiel.
the following form
<form enctype="application/x-www-form-urlencoded" method="POST" action="/submit">
 <input type="text" name="name" value="Bob"><br>
 <input type="text" name="surname" value="DOE"><br>
 <input type="submit" value="Send">
</form>

so accepted
if(req.url == '/submit' && req.method == 'POST') {
 req.on('data', function(data){
 var s = decodeURIComponent(data.toString());
console.log(s);

 var obj = {};
 var arr = s.split('&');
 arr.forEach( el => {
 var a = el.split('=')
 obj[a[0]] = a[1];
});
console.log(obj);
});
 return res.end('POST');
 }

with this result
name=Bob&surname=DOE
{ name: 'Bob', surname: 'DOE' }

you need to drink...
Thank you. This method has worked. - Ahmad.Lueilwi commented on June 3rd 19 at 20:27
June 3rd 19 at 20:26
https://habr.com/post/327440/

but that would be a pain in the ass wild, where fear of the extra modules?

It is better to write a bunch lapchild that nobody will understand than to take the package ready in a couple of lines to make the routing?

Find more questions by tags Node.js