I'm having an issue where I'm attempting to update a json object with text received from user input in a prompt, however the prompt function does not seem to work in the index.js file, but works everywhere else. Here's the code I have within the post function:
router.post('/save/:id', function(req, res, next) {
data = window.prompt();
projectData[0].name = data;
fs.writeFile('data/data.json', JSON.stringify(projectData), 'utf8', function(err) {
if (err) {
console.log(err);
}
});
res.json(projectData);
});
I know the code works because if I just set projectData.[0].name to a string value, it updates the json object value in the data.json file appropriately. Anyone have any idea why the prompt function isn't working in this file specifically? The prompt function works fine in the mainclient.js file, just not here. Alternatively, could anyone help by telling me how to pass a variable value from another file into the index.js file? Any help would be appreciated as I'm new to javascript and web development. Thanks!
windowobject: remember nodejs is server sided and is not run by the browser.promptdoes not make sense on the server side. It does not exist.