2

I'm trying to create and write to a file in a folder outside of node app's source folder.

I have a absolute path like this E:\myFolder\ but when I try to writeFile with fs it throws ENOENT error.

I've created E:\myFolder manually, but I think the problem is my app can't see outside of it's own folder.

Any way to solve this?

kecman
  • 813
  • 3
  • 14
  • 34
  • 1
    Writing files is not limited to the app folder, but you need to make sure that you escape the paths properly (`fs.writeFile('E:\\myFolder\\myFile.txt', ...)`). Backslashes have a special meaning in JS scripts. – robertklep Apr 17 '17 at 13:35
  • I've escaped it, but now I came upon conclusion that problem is because in filename there are some illegal characters like ":". What is a standard way to remove all illegal characters from filename string? – kecman Apr 17 '17 at 13:40
  • There isn't really a standard way, but there are [various packages](https://npms.io/search?q=clean+filename) that can help you. – robertklep Apr 17 '17 at 13:47
  • Thanks. If you want, you can make your comments a answer so I can accept it. – kecman Apr 17 '17 at 13:49

0 Answers0