Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Heroku app is not recognizing/reading myfile.txt

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!