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')

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.

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 *