0

I am unable to understand the concept and use of '/' ,'./' and '../' in node.js. Help me to understand it in easy way. i have a folder fyp in which some files are present and another folder login within that folder and from the files in login folder i want to access file 'welcome.html' of fyp folder by using response.sendFile(__dirname + 'welcome.html'). but i don't know how to access this file and it is showing error.

app.get('/', function(request, response) { response.sendFile(__dirname + 'welcome.html'); });

palo
  • 159
  • 2
  • 12
  • 1
    Welcome! Those terms are usually referencing file directory navigation. This has some good write up on that. https://stackoverflow.com/questions/7591240/what-does-dot-slash-refer-to-in-terms-of-an-html-file-path-location . app.get('/', ...) is making a network call to '/' where the host is wherever the service is running. So if you are running locally, it will try and call http://localhost:/ . If you were on a server it might try something like https://serverHostName:/. Where the slash on the end is that slash in the app.get('/') – canpan14 Mar 02 '20 at 14:29

1 Answers1

0

in your case you are just concatenating two strings: one from __dirname and one 'welcome.html' defined by you.

you can use path.join([...paths]) from 'path' nodejs module to work with relative paths. read more here

Yone
  • 867
  • 1
  • 7
  • 22