I have a simple app on Heruku that show an image.
app.js
package.json
package-lock.json
public
|__ image1.png
|__ image2.png
Here is the content of app.js
const express = require('express');
const app = express();
const path = require('path');
app.set('port', (process.env.PORT || 5000));
app.use(express.static('public'));
app.get('/', function(request, response) {
const today = new Date().getHours();
const img = today <= 13 ? 'image1.png' : 'image2.png';
response.sendFile(path.join(__dirname, '../public/' + img));
});
In the Heroku log I get this error: Error: ENOENT: no such file or directory, stat '/public/image1.png'
I have made a lot of tries, following these answers:
- https://stackoverflow.com/a/40931927/2516399
- https://stackoverflow.com/a/25463996/2516399
- https://stackoverflow.com/a/26079640/2516399
None of these do the trick in my case. What could be wrong?