1
Public Directory Node.js
I’m having problems releasing a public directory on Node.js. I need everything in the directory public is accessible via direct URL.
I’ve tried to use app.use(express.static('public'));
however unsuccessfully.
I’m using these dependencies:
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.3",
"mssql": "^4.1.0",
"multer": "^1.4.1"
}
The file should be accessed by some URL similar to:
- http://localhost:3020/query advanced/public/uploads/nfd/1550581279905_boleto.pdf
- http://localhost:3020/query advanced/uploads/nfd/1550581279905_boleto.pdf
Or Node does not have this support?
EDIT 1: Adding Images.
Index.js:
Folder Structure:
Route:
thanks for the help. But I tested both ways and it didn’t work. From what I saw on the internet this would work in case I want to import js, css or img files to the page in question. But what I really want is that I can access this PDF directly through the link, outside the site.
– Pedro Daher
I edited the question to add images, see if it helps better so... Anything I put more information if you need.
– Pedro Daher
I added the folder structure and routes
– Pedro Daher
@Pedrodaher out that your URL seems to be wrong. Make the call without the
consultaavancada
:http://localhost:3020/public/uploads/nfd/1550581279905_boleto.pdf
– Sorack
I made the call without the
consultaavancada
and it wasn’t either, but I think I should keep it, because on the route it is configured.– Pedro Daher
@Pedrodaher tried both ways without the
consultaavancada
?– Sorack
I tested yes, I did a test added the
consultaavancada
in the code you posted up there, gettingapp.use('/consultaavancada/public', express.static(path.join(__dirname, 'public')));
and it worked. You saved me man!! Thank you so much.– Pedro Daher