Absolute vs. Relative Paths
Absolute paths start with / and point to the root of your site. A URL is a prime example of an absolute path.
Relative paths do not start with / and point to a location relative to the document that the path reference is made in.
If the root is: http://localhost:3000/
Then an example of an absolute path is:
/index.html
Which points to: http://localhost:3000/index.html
An example of a relative path:
../views/login.html
If the relative path is in a document located in: http://localhost:3000/public
Then it points to: http://localhost:3000/views/login.html
__dirname
I’m sure many of you have seen:
app.use(express.static(__dirname + '/'));
Node.js populates the global namespace with ‘__dirname’, which refers to the name of the directory that the currently executing script resides in, i.e. where this server is.
So if you have // /Users/me/desktop/coding/project/server/server.js then if we console.log __dirname within server.js our console will show ‘/Users/me/desktop/coding/project/server/’.