Skip to content
Advertisement

Appending array to JSON file with JavaScript

Now I dont have any other choise. Everything seems right in my eye. Still not working.

I am doing little food app for myself to get know how much i’ve eaten. I created JSON file named ruoat.json, where I going to add foods via app. I have done this earlier with PHP and it was quite easy. But now doing this with JavaScript gives me a gray hair.

Tried few different ways find from Google, no any working solution.

Where is the problem?

JavaScript

Advertisement

Answer

I can see that you are using the fs module, which is a part of Node.js. Nodejs does not support the document object because it is designed to be run outside a browser. That aside, it would work if you didn’t do the file business and ran it in a browser

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement