So I'm having this code as a base and I have to use it to convert the content of "world_data.csv" to JSON.
I don't have a clue about how I can save that JSON in a variable. I guess the data I want is stored temporarly in "jsonArray", but how can I define a global variable which stores that data indefinetely?
var express = require('express');
var app = express();
var sys = require('util');
var path = require('path');
var bodyParser = require('body-parser');
var Converter = require("csvtojson").Converter;
app.use( bodyParser.json() );
app.use( express.static( path.join(__dirname, "public") ) );
var converter = new Converter({});
converter.on("end_parsed", function (jsonArray) {
console.log(jsonArray);
});
require("fs").createReadStream("world_data.csv").pipe(converter);
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});