I am writing JSON objects to a file that are streaming from the twitter api. They log to the console correctly and look like JSON objects; however, when I use the command:
fs.appendFile("./tweets.json", tweet) All that writes to the file is the following:
[object Object] What is going on here? When I write the object tweet to console, this is the output:
{ created_at: 'Tue Mar 17 22:12:41 +0000 2015', id: 577955743997018100, id_str: '577955743997018112', text: ......tons more stuff.... filter_level: 'low', lang: 'en', timestamp_ms: '1426639434951' } What is [object Object] and why is it writing that?
[object Object]in your file thentweetis not a string containing data in theJSONformat, but a regular javascript object. And the console output :{ created_at: 'Tue Mar 17 22:12:41 +0000 2015',shows clearly that it is notJSON. In aJSONformatted string thekeyneeds to be quoted with double-quotes.