I am parsing an array from an API in Node and then handling it to my HTML file so I can draw on a map some points I received from the API. I want to pass as a parameter the array so the HTML receives it. I've looked through all the other possible answers here but none worked.
index.js
const express = require('express')
const util = require('util')
var request = require("request")
var path = require('path')
const app = express()
app.get('/_bicis', (req, res) => {
var url = "https://nextbike.net/maps/nextbike-official.json?city=532"
request({
url: url,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
data = body['countries'][0]['cities'][0]['places']
res.sendFile(path.join(__dirname + '/index.html'), {data: data});
}
})
})
module.exports = app
index.html file
<html><head>
</head>
<body>
<script>
// When printing this line it raises an error
console.log("RECEIVED FROM HTML" + data)
</script>
</body></html>
I am not using any template to generate my HTML file, should I? Can it be done with the code I have?
dataisn't declared in that program.