I have created an express app which successfully displays JSON on Windows - I have had no problem on Firefox or Chrome. However, when I try to run the same code on my linux setup (Debian) or deploy it on Heroku, receives an empty array: []. How can I get it to display on more than just windows? Here is the js file:
var express = require('express');
var router = express.Router();
var fs = require('fs');
//read file of chore todos
function readCSV(callback) {
fs.readFile('./data/todoList.csv', function(err, data) {
if(err) throw err;
var dataStr = data.toString();
var array = dataStr.split("\n");
fs.writeFileSync('./data/todo.json', JSON.stringify(convertToJSON(array), null, 4));
var temp = convertToJSON(array);
return callback(temp);
});
}
//convert array to JSON
function convertToJSON(array) {
var rows = array.toString();
rows = rows.split("\r");
for (var i=1; i<rows.length;i++) {
rows[i] = rows[i].replace(rows[i][0], "");
}
var asJSON = [];
// get column headers
var headers = rows[0].split(",");
for (var i=1; i<rows.length-1; i++) {
var obj = {}
var currentRow = rows[i].split(",");
for (var j=0; j<headers.length; j++) {
obj[headers[j]] = currentRow[j];
}
asJSON.push(obj);
}
return asJSON;
}
var returnJSON;
readCSV(function(temp) {
returnJSON=temp;
})
router.get('/', function (req, res, next) {
res.json(returnJSON);
});
module.exports = router;


