I'm using request to make a api call, and return some data to my app. I'm able to receive the data in the body response of my code
var express = require('express');
var request = require('request');
var app = express();
app.get('/', function(req, res){
res.sendFile(__dirname + "/index.html");
request('https://api.darksky.net/forecast/apikey/37.8267,-122.4233', function (error, response, body) {
console.log('error:', error);
console.log('statusCode:', response && response.statusCode);
console.log('body:', body);
});
}).listen(3000);
console.log('Server is up and running');
The api call is made then i hit my index file at / - so far, so good
However i want to send the body response, with my data, to a react js file, so i can use the data to serve to the client. I can't seem to find any help on how to serve data to another javascript file.
app.getroute specifically for returning the data you receive from the api.darksky.net request, to separate it from your homepage route returning index.html. In that, you canreturn res.json(body)