Categories
JavaScript Answers

How to convert relative path to absolute with Node.js?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.