Hello I'm simply trying to have a welcome message that gets updated via POST, and as far as I can tell I'm sending a JSON from my Client side JavaScript, and on my NodeJS side it shows as [object object] I've tried req.body and that comes back with "undefined". I'm wondering how I would be able to extract my welcome message from the JSON i'm sending to the nodejs server and save to a .JSON to be able to be pulled later from the client.
I've tried doing jsonstringify(req) and that returns a big error in my nodejs cmd which I can paste if that may be necessary.
nodejs server POST, and it will write to the file welcome.json, it will either write [object object] or undefined, based on if I use req.body or req.
app.post('/update', function (req, res) {
fs.writeFile(__dirname + '/rqsts/welcome.json', req.body, function () {
console.log('We got a Post request' + req.body);
});
});
and here is my client side http post request:
function submit() {
var text_Input = document.getElementById('textinput').value;
var testing = document.getElementById('testme');
var welcome_array = {
welcome: ""
};
welcome_array.welcome = text_Input;
var welcomeJSON = JSON.stringify(welcome_array);
var url = 'http://localhost:8080/update';
var http = new XMLHttpRequest();
http.open('POST', url, false); // false for synchronous request
Add_Para(welcomeJSON, testing);
http.send(welcomeJSON);
}
the Add_Para is a function I made to troubleshoot, it adds a paragraph to said html with the requested data "welcomeJSON"