0

Now I have code like this api call, the social network vk.com:

// Setup
var fs = require('fs');
var VK = require('vksdk');

var vk = new VK({
    'appId': ********,
    'appSecret': '*****************',
    'language': 'ru'
});


vk.oldRequest("photos.get", {
    owner_id: "-28445240",
    album_id: "wall",
    rev: "1",
    extended: "1",
    version: "5.40",
}, function (data) {
    console.log(data);
});

In the console output json. How to write it to a file.

Nikita Ivanov
  • 31
  • 1
  • 1
  • 4

2 Answers2

0

You need to give JSON.stringify(anyObject) to fs.writeFile in order to save an object to a file, otherwise, you will get the string [object Object] (the result of Object.prototype.toString())

axelduch
  • 10,769
  • 2
  • 31
  • 50
0

You need to do two things:

var fs = require('fs');
fs.writeFile("data.json", JSON.stringify(data, null, 2), function(err) {
    if(err) { return console.log(err); }
});
Kristján
  • 18,165
  • 5
  • 50
  • 62