I have a function that allows you to create a folder in the directory where the server is located, and upload files there
And I’m trying to access them via a direct link, like this
Because, the file is located here
But why can’t I access it?
Cannot GET /attachments/1618413024408--1.jpg
Express itself provides an easy to use implementation for this
Simply add this add the right position in your code:
app.use('/attachments', express.static(path.join(__dirname, 'attachments')))
Make sure that
path.join(__dirname, 'attachments') points to the right directory (with a simple console.log) otherwise just adjust it.