T
T
Torento203452021-06-08 11:53:45
Express.js
Torento20345, 2021-06-08 11:53:45

Why does the server give an error when trying to go back a folder?

How to make a root directory, which is the parent folder of the folder in which we have a server file?
Such code throws an error, like others with attempts to get into the folder before.

const app = express();
app.use(express.static('../public'));
app.get('/', function (req: Request, res: Response) {
  res.sendFile(`${__dirname}/../public/index.html`);
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2021-06-08
@Torento20345

res.sendFile('index.html', { root:  path.resolve(__dirname, '../public/index.html') })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question