Home > Software engineering >  Node fs.readdirsync read directory in npm package
Node fs.readdirsync read directory in npm package

Time:07-04

i tried to use fs.readdirSync and it work perfectly, but when i publish to npm and install this package to my new project, it not read my package directory instead it will read from my new project directory.

My goal is to get list file names inside package directory not new project directory

const dirents = fs.readdirSync("./", { withFileTypes: true });
console.log(dirents)

CodePudding user response:

You need to use __dirname because it is an environment variable that tells you the absolute path of the directory containing the currently executing file.

Instead of using ./ it will represent your current working directory

  • Related