YannisP
YannisP

Reputation: 69

Node & Express - Access files from higher directory

This is my server's structure:

index.js
admin
|_ admin.html
public
|_ index.html
uploads
|_ some files...

and this is part of my server's code:

app.use(express.static(__dirname + '/public'))
app.use(express.static(__dirname + '/admin'))
app.use(express.static(__dirname + '/uploads'))

How can admin.html or index.html have access to the files from the uploads directory?
Because what I'm already doing doesn't seem to work. Specifically, images that originate from the uploads folder never show in either admin.html or index.html.

Upvotes: 1

Views: 510

Answers (1)

Amardeep Kamble
Amardeep Kamble

Reputation: 26

Assuming same folder structure with images folder in uploads and one image img.jpg

index.js
admin
|_ admin.html
public
|_ index.html
uploads
|_ images
  |_ img.jpg

As you are already serving public, uploads and admin folders as static, in html file can use

<img src="images/img.jpg" alt="" />

Upvotes: 1

Related Questions