Categories
JavaScript Answers

How to go back 1 folder level with __dirname with JavaScript?

Spread the love

Sometimes, we want to go back 1 folder level with __dirname with JavaScript.

In this article, we’ll look at how to go back 1 folder level with __dirname with JavaScript.

How to go back 1 folder level with __dirname with JavaScript?

To go back 1 folder level with __dirname with JavaScript, we can use the '../ string.

For instance, we write

const path = require("path");
const p = path.join(__dirname, "../");

to call path.join with __dirname and "../" to return a string with the path one level up from __dirname.

Conclusion

To go back 1 folder level with __dirname with JavaScript, we can use the '../ string.

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 *