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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *