I am facing an issue while trying to access an HTML file from my main directory through my Express server, which is located one level deeper in the server folder. Below is the configuration of my server code:
const express = require('express');
const app = express();
app.use(express.json());
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
})
const port = 5000;
app.listen(port, () => console.log(`Server is listening on port ${port}.`))
The error message I am encountering is as follows:
Error: ENOENT: no such file or directory, stat '/mnt/c/Project-Directory/server/index.html'
This error clearly explains why I cannot access my HTML file; my server is located in the /server folder whereas my index.html file is present in the Project-Directory folder. However, I am uncertain about how to access my HTML file from its current location.