"absolute path" <-- starts from "root" directory

How far back do we mean when we says an 'absolute' path goes to the 'root' directory? In the context of an ExpressJS app.. Would the "root" be the project folder correct? And if so, how does it know to stop there and consider that the 'root'. Is it looking for some identifying file or something? Like package.json?
13 Replies
Jochem
Jochem•2y ago
root in the context of backend filesystem is / same for a domain actually, it's just the domain (so https://google.com/ is the root of anything below google.com) for the filesystem, that's the linux filesystem root, so if your project lives in /var/www/html/my-cool-project/, the index.html's file absolute path is /var/www/html/my-cool-project/index.html
thethingisback
thethingisbackOP•2y ago
so from my app.js.. I'm using an app.get() to get my index.html. The app.js and the index.html are on the the same 'level' in the filesystem.. so the first argument of .get(), the path, is just '/'... And then when I'm using res.sendFile(), which requires an absolute file path, I use path.resolve(), which returns an abs path. But I'm wondering how path.resolve() knows where the 'root' is?
Jochem
Jochem•2y ago
it's always at /
thethingisback
thethingisbackOP•2y ago
so is it fair to say the 'root' is always the folder that the app.js is in... in other words "/" will always be whereever app.js is?
Jochem
Jochem•2y ago
no, that's a relative path / is the equivalent of C:\ in windows path.resolve produces an absolute path that starts at the root of the filesystem you're on, which on a linux machine is always /, the very beginning of any path and where all the files live
thethingisback
thethingisbackOP•2y ago
but where is that beginning though, are we talking about the root of the whole computer filesystem? Because even my project folder is itself inside of other folders? "where all files live" of the project?
Jochem
Jochem•2y ago
the whole computer
thethingisback
thethingisbackOP•2y ago
ahhhh
Jochem
Jochem•2y ago
absolute paths are a unique way to identify any file on your computer
thethingisback
thethingisbackOP•2y ago
gotcha okay.. so path.resolve() gives the path to the file at a 10,000ft 'whole computer' level
Jochem
Jochem•2y ago
yes
thethingisback
thethingisbackOP•2y ago
okay great that makes more sense then, I'd been thinking it was from the 'root' of the project this whole time thank you thank you
Jochem
Jochem•2y ago
no worries 🙂
Want results from more Discord servers?
Add your server