javascript - Not able to pass an object in writeFile method -


i want write json file .i want write object passing here code

path.exists(logfile_name, function(exists) {     if (!exists) {          var jsonobject={ "req": req,                      "result": result ,                       "fields": fields } ;              fs.writefile(logfile_name ,jsonobject,function(err){             if(err){                 console.log("error is: " + err)             }             else                 console.log("no error found");               });     }  }); 

in logfile_name writes [object object] want write { "req": value, "result": value , "fields": value}

if don't pass string or buffer writefile, tostring function of pass called. in case returns "[object object]".

you have convert :

fs.writefile(logfile_name, json.stringify(jsonobject), function(err){ 

i advise against naming javascript object variable "jsonobject" : might create confusion between object , json (i.e. string holding serialization of object).


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -