Создаем файл hello_http.js со следующим содержимым
var port = 8080;
var http = require("http");
var server = http.createServer();
server.on('request', request);
server.listen(port, (err) => {
if (err) {
return console.log('something bad happened', err)
}
console.log(`server is listening on ${port}`)
})
function request(request, response) {
var store = '';
request.on('data', function(data){
store += data;
});
request.on('end', function(){
var js_name = JSON.parse(store);
console.log(js_name['name']);
//response.setHeader("Content-Type", "text/json");
//response.setHeader("Access-Control-Allow-Origin", "*");
//response.end(store)
//store = JSON.parse(store);.
response.end('city: '+js_name['address']['city']);
});
}