javascript - Add object to an array in a JSON `file` in Node.js for each request -


i have image on frontend. when user right clicks on image, coordinates of point stored in variable , variable sent node server using ajax post request. in server side storing x,y coordinates file objects. want keep on piling set of x,y coordinates same file different objects previous, when user right clicks @ other places on image. problem when right click on other position, coordinates of point replacing previous ones in file, instead of adding file , keeping previous ones well. how can achieve that?

.post(function(request, response){     console.log("request received");     var util = require('util');     var coordinates = request.body;     var imagecoordinates = json.stringify(coordinates);     fs.writefile('coords.json', imagecoordinates, finished);      function finished(err){         console.log('all set.');     }      console.log('coords are:', coordinates);             response.send("all ok"); });  

this request handler function in server.js file.

fs.writefile: asynchronously writes data file, replacing file if exists.

fs.appendfile: asynchronously append data file, creating file if not yet exist.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -