E
E
EVOSandru62020-04-14 23:04:54
Express.js
EVOSandru6, 2020-04-14 23:04:54

How to access image in NodeJs/Express server?

Good afternoon.

There is a simple server structure:

- src
- - data
- - - images
- - - - 1.jpg
- - - - 2.jpg
- - - - 3.jpg

What needs to be done. so that when the server is running, typing in the address bar for example:

localhost:4006/images/1.jpg

See the picture?

You don't need to download it, just display it. You need to display it on the client.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-04-14
@EVOSandru6

https://expressjs.com/en/starter/static-files.html
with a folder structure like this

app.use('/images', express.static(path.join(__dirname, 'src', 'data', 'images')))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question