0

I have several files on my server located at /var/www/files/
My vuejs is in ~/Dev/app
I did : let file = require('/var/www/files/myfile.jpg')
then npm run build my app.
But I have this error 🫣 :

Error: Cannot find module '/var/www/files/myfile.jpg' 

I can access my files when they are in ~/Dev/app/public/ tho 😅

To add a bit more clarity : I want my user to download a file from my server to its web browser. I can do that when the file is in the project /public but not when it's somewhere else on the server.

4
  • Consider explaining your case, see stackoverflow.com/help/how-to-ask . It's unknown what's your setup, while it's relevant. Generally you have all the files that you import inside the project. Why are they located at /var/www/files/ ? In case you need them in both places, use fs links Commented Sep 25, 2024 at 15:29
  • I can't move from where they are but I need to access them. I wish I could have done things my way but this is how the legacy code I'm working on works. Commented Sep 26, 2024 at 6:08
  • As I said, you can create a link to make files available inside project hierarchy Commented Sep 26, 2024 at 8:04
  • You need to provide it on a public url, or to handle it via an intermediary. Commented Oct 3, 2024 at 15:02

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.