1

I have installed a NodeJS module on a Digital Ocean Droplet. It generates a csv file that I store in the directory root/csv_file/my_file.csv.

However, I cannot access it in the browser by simply visiting ip_address/csv_file/my_file.csv.

I read this question which asks me to install http-server so I installed it. After that I ran the following command:

http-server csv_file

and

http-server root

However, none of the allowed me to access the file by visiting root/csv_file/my_file.csv.

Using the file_get_contents() function in PHP gives me the following error:

No connection could be made because the target machine actively refused it.

How can I access this file preferably in PHP or in browser?

Thanks.

Real Noob
  • 1,369
  • 2
  • 15
  • 29

1 Answers1

1

http-server csv_file will serve in port 8080 by default. Did you try http://your_ip_address:8080 Please make sure: the port is already opened/allowed (https://askubuntu.com/questions/911765/open-port-on-ubuntu-16-04)

Thang Duc
  • 316
  • 1
  • 5
  • Thanks Thang. :) Will I have to always run `http-server csv_file` in console before I can access the file in browser or using PHP? – Real Noob May 20 '20 at 05:06
  • Thanks Thang. Just one more question. :) Will I have to **always** run `http-server csv_file` in the terminal before I can access the file in browser ? – Real Noob May 20 '20 at 07:22
  • 1
    yes, have to run it to serve your files. But It will be turned off when you close your terminal or exit. Please use `pm2` to keep it alive. https://stackoverflow.com/questions/31804966/running-nodejs-http-server-forever-with-pm2 it will take some time to know `pm2`, but `pm2` is really great for nodejs apps – Thang Duc May 20 '20 at 07:40