For my school project, I am utilizing IBM Bluemix to develop a web service.
The core of my project requires fetching a JSON from an API in order to utilize the provided data.
My main challenge lies in the HTTP request to the API service, as I encounter the following alert in the Windows 10 Command Prompt.
"Syntaxerror: Unexpected Token"
I am aware that there is an issue with my JSON request, but pinpointing the exact problem proves to be difficult.
Provided below is my .js
file along with a screenshot displaying the error message upon execution.
/*eslint-env node*/
//------------------------------------------------------------------------------
// Starter application for Bluemix
//------------------------------------------------------------------------------
var http = require('http');
var request = require('request');
var cfenv = require('cfenv');
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/public'));
var appEnv = cfenv.getAppEnv();
app.listen(appEnv.port, '0.0.0.0', function() {
console.log("server starting on " + appEnv.url);
});
app.get('/home1', function(res){
http.get('http://developers.agenciaideias.com.br/cotacoes/json', function(res){
var body = '';
res.on('data', function(chunk){
body += chunk;
});
res.on('end', function(){
var json = JSON.parse(body);
});
var json = JSON.parse(res);
var cotacao = json["bovespa"]["cotacao"];
console.log("Your quotation is "+cotacao);
});
});