Languages
[Edit]
EN

Node.js - get relative path to indicated path

0 points
Created by:
Nathanial-Donald
584

In this article, we would like to show you how to get a relative path from one location to another in Node.js.

1. Import path module using:

2. Use path.relative() method to get the relative path from from to to based on the current working directory.

Relative path to file:

Output:

Note:

Thanks to the path we got, we are able to access the background.png file in the src folder.

Relative path to directory:

Output:

Note:

Thanks to the path we got, we are able to access the resources directory in the src folder.

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join