Categories
JavaScript Answers

How to get folder path from a file with Node.js?

Spread the love

To get folder path from a file with Node.js, we call the path.dirname method.

For instance, we write

const path = require("path");
const dir = path.dirname("G:\\node-demos\\7-node-module\\demo\\config.json");

to call path.dirname to return the folder path for the "G:\\node-demos\\7-node-module\\demo\\config.json" path.

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 *