0

I am inside of a folder src and want to create files insides another folder called dist. Below is what I want to do from inside the src folder. Create a json file inside of dist/JSON/{file goes here}

main
- src
  index.js
- dist
  - JSON
    file.json

So my code is:

const file = path.resolve(__dirname, `/dist/JSON/${filename}.json`);
await fs.outputJson(file, {name: "name"})

This is putting the file however inside of src/dist/JSON/${filename}.json and I want dist/JSON/${filename}.json

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Taylor Austin
  • 5,407
  • 15
  • 58
  • 103

1 Answers1

1

Since you want to go to the parent directory before navigating, you should add ../ to your path.resolve() and it should fix your issue.

const file = path.resolve(__dirname, `../dist/JSON/${filename}.json`);
await fs.outputJson(file, {name: "name"})
Sunny Patel
  • 7,830
  • 2
  • 31
  • 46