NOTE. This is not a duplicate question; I have already tried other answers to similar questions.
I am trying to display html files (Angular) but I am having a problem. It works.
app.get('/randomlink', function(req, res) {
res.sendFile( __dirname + "/views/" + "test2.html" );
});
But I don’t want to copy and paste the dirname thingy again and again, so I tried this so as not to repeat with the urls:
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'views')));
app.get('/randomlink', function(req, res) {
res.sendFile('test2.html');
});
This is a mistake.
My express version 4.13
the path must be absolute or specify root for res.sendFile
source
share