I am using an externally referenced Javascript file which is in the same directory as my HTML file.
My javascript program reads some data from a ".txt file" and stores them in variables speed,altitude & pressure. I wish to display the values of these variables in my HTML. But for some reason this is still not working.
Javascript Code:
var fs = require('fs');
fs.readFile('data.txt', 'utf8', function(error, data) {
var content = data;
console.log(content);
var obj = JSON.parse(content);
var speed = obj.speed_json;
console.log(speed);
var altitude = obj.altitude_json;
console.log(altitude);
var pressure = obj.pressure_json;
console.log(pressure);
});
document.getElementById("pressurehtml").innerHTML = altitude;
document.getElementById("speedhtml").innerHTML = speed;
document.getElementById("altitudehtml").innerHTML = pressure;
HTML Code:
<html>
<body>
<h1 id="pressurehtml">Pressure</h1>
<h1 id="altitudehtml">Altitude</h1>
<h1 id="speedhtml">Speed</h1>
<script src="main.js"></script>
</body>
</html>