0

I was wondering if its possible to get a file from the local file system (where node is running) using HTTP GET?

Meaning using a package such as axios, or request to get the file

The path to the file is full path.

Mr Wigg
  • 41
  • 2
  • 9

1 Answers1

1

Yes, check out the fs module..

Evert
  • 93,428
  • 18
  • 118
  • 189
  • I'm familiar with fs, but what will happen if the url is an actual web url? I suppose the call to fs will throw an error, no? – Mr Wigg Oct 02 '20 at 05:56
  • 1
    fs is for local file-system. You should perform a string check and make sure the path your passing into fs is valid and not a web url before you attempt to read file system. Either way if the fs fails it will throw an error that you can catch/read.You can use a simple npm lib like https://www.npmjs.com/package/is-url ... If it returns boolean true then dont read the file-system. Or if you dont care then just let fs return the error when it fails to find the file. – jremi Oct 02 '20 at 05:57
  • Okay, so this was my implemetation idea. But I wanted to make sure there's no way to avoid the string check – Mr Wigg Oct 02 '20 at 05:59
  • Read my last comment. You can do a string check against the url before sending the file path into fs – jremi Oct 02 '20 at 05:59