How to go back 1 folder level with __dirname in Node.js?

Sometimes, we want to go back 1 folder level with __dirname in Node.js.

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

How to go back 1 folder level with __dirname in Node.js?

To go back 1 folder level with __dirname in Node.js, we can use the path.join method.

For instance, we write

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

to call path.join with __dirname and "../../../" to return the path of the folder that’s 3 levels above __dirname and assign it to reqPath.

Conclusion

To go back 1 folder level with __dirname in Node.js, we can use the path.join method.