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");
const absPath = resolve("../../bb/tmp.txt");
to call resolve
with a relative path to return a string with the equivalent absolute path.
Conclusion
To convert relative path to absolute with Node.js, we can use the path
module’s resolve
function.