Answer the question
In order to leave comments, you need to log in
How to process a POST request without unnecessary require'ov?
I want to process POST request with NodeJS and http module, how to do it without extra modules?
Answer the question
In order to leave comments, you need to log in
O! I washed down the materiel.
this is the form
<form enctype="application/x-www-form-urlencoded" method="POST" action="/submit">
<input type="text" name="name" value="Вася"><br>
<input type="text" name="surname" value="Пупкин"><br>
<input type="submit" value="Send">
</form>
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');
}
name=Вася&surname=Пупкин
{ name: 'Вася', surname: 'Пупкин' }
https://habr.com/post/327440/
but it's like a wild crap, where does the fear of extra modules come from?
Is it better to write a bunch of noodle code that no one will understand than to take a ready-made package and arrange routing in a couple of lines?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question