UNIX absolute path starts with '/', whereas Windows starts with alphabet 'C:' or '\'. Does node.js has a standard multiplatform function to check if a path is absolute or relative ?
This just checks if the path string has either "/./" or "/../". and returns true on any and false on neither. If any of the two tests is true then the path string is relative.
path. isabs() method in Python is used to check whether the specified path is an absolute path or not. On Unix platforms, an absolute path begins with a forward slash ('/') and on Windows it begins with a backward slash ('\') after removing any potential drive letter.
Since node version 0.12.0 you can use the path.isAbsolute(path)
function from the path module.
i.e:
var path = require('path'); if(path.isAbsolute(myPath)) { //... }
You could use
path.resolve(yourPath)===yourPath
If your path isn't normalized, use
path.resolve( yourPath ) == path.normalize( yourPath )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With