Categories
JavaScript Answers

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

Spread the love

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

For instance, we write

const path = require("path");
const configFile = path.join(__dirname, "../test/karma.conf.js");

to call path.join with __dirname and a string with the path one level above __dirname with ../ to return a path one level above __dirname.

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 *