0

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!

5
  • There is no such thing as a JSON object. There is JSON, and there are JavaScript objects. Don't confuse the two. Commented Dec 10, 2016 at 9:49
  • 1
    Is this nodejs? In that case, there is no window object: remember nodejs is server sided and is not run by the browser. Commented Dec 10, 2016 at 9:50
  • Thank you for the clarification. Yes, this is in node.js. Sorry, I attempted it with and without the window prefix. Doesn't work either way. Commented Dec 10, 2016 at 9:51
  • 1
    Of course, prompt does not make sense on the server side. It does not exist. Commented Dec 10, 2016 at 9:53
  • But if you want to prompt message to client, you have to call it on client side, not server... That's the same than here Commented Dec 10, 2016 at 9:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.