I just deployed my app on heroku, my txt file is not recognized/read? and it's working perfectly fine on my local machine. Is there a reason for it? this is the structure of the documents:
-app
-css
-files
--myfile.txt
-js
-logo
-views
-index.html
-app.js
-composer.json
-package-lock.json
-package.json
-Procfile
this is my app.js:
const express = require('express');
const PORT = process.env.PORT || '8080';
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, 'app')));
app.get('/', (req, res) => res.render('index'));
app.get('/profiles', function(request, response){
response.json(
getFileContents()
);
});
function getFileContents(){
// Buffer mydata
var BUFFER = bufferFile('./app/files/myfile.txt');
return processData(BUFFER);
}
//read file
function bufferFile(relPath) {
var fs = require('fs');
var path = require('path');
return fs.readFileSync(path.join(__dirname, relPath),{ encoding: 'utf8' });
}
function processData(contents){
let data = [];
contents.split("\r").forEach( line => {
let row = line.replace('\n','').split('\t');
data.push(
{
Name : row[0] || '',
City : row[1] || '',
Links : row[2] || ''
}
)
});
return data;
}
app.set("port", PORT);
app.listen(PORT, () => console.log(`Listening on port ${PORT}`));
anyone has any idea why it's not working? Thanks in advance