Node js using api example

Previously I asked for help using the api but I figured it out. Node Js example.

var request = require("request");
var fs = require("fs");


var options = { method: 'GET',
    url: 'https://api.twitch.tv/kraken/streams/',
    qs: { game: 'Fortnite', offset: '0', limit: '2' },
    headers:
        { 
            'Client-ID': 'insert client id here' } };

request(options, function (error, response, body) {
    if (error) throw new Error(error);
    fs.writeFile('./myfile.csv', body, { flag: 'w' }, function(err) {
        if (err)
            return console.error(err);
        fs.readFile('./myfile.csv', 'utf-8', function (err, data) {
            if (err)
                return console.error(err);
            console.log(JSON.parse(data));
        });
    });
});

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.