Skip to content
Advertisement

Node.js: get path from the request

I have a service called “localhost:3000/returnStat” that should take a file path as parameter. For example ‘/BackupFolder/toto/tata/titi/myfile.txt’.

How can I test this service on my browser? How can I format this request using Express for instance?

JavaScript

Advertisement

Answer

JavaScript

I have not tested your code but other things works

If you want to get the path info from request url

JavaScript

1.If you are getting the URL parameters still not able to read the file just correct your file path in my example. If you place index.html in same directory as server code it would work…

2.if you have big folder structure that you want to host using node then I would advise you to use some framework like expressjs

If you want raw solution to file path

JavaScript

source : http://www.nodebeginner.org/

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement