Sometimes, we want to convert relative path to absolute with Node.js.
In this article, we’ll look at how to convert relative path to absolute with Node.js.
How to convert relative path to absolute with Node.js?
To convert relative path to absolute with Node.js, we can use the path
module’s resolve
function.
For instance, we write
const {
resolve
} = require('path')
resolve('../../dir/tmp.txt')
to call resolve
with a relative path string to return the absolute path equivalent of the relative path as a string.
Conclusion
To convert relative path to absolute with Node.js, we can use the path
module’s resolve
function.