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.

3
  • 1
    Well, did you try fs.writeFile(filename, data, [encoding], [callback]) ? Commented Dec 6, 2015 at 18:54
  • stackoverflow.com/questions/5726729/… Commented Dec 6, 2015 at 18:54
  • after fs.writeFile , my file contain: [object Object] Commented Dec 6, 2015 at 19:09

2 Answers 2

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())

Sign up to request clarification or add additional context in comments.

Comments

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); }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.