I want to be able to create a text file and save it in a particular location using HTML and Javascript. I want to download the file into the location which I specify in the code, without changing the browsers settings. I want to be able to do this on Node JS.
Asked
Active
Viewed 1,945 times
-2
-
Please ask a specific question about your code, and post your code. – Jonathan M Mar 01 '17 at 19:17
-
what you're asking for is not possible, nor allowed by browsers because that's a safety violation. For example, if you can change the directory location you can also change the name, let's say you create a file called loveletter.txt, now you could save it as /etc/hosts or C:/windows/system32/etc/hosts or something like that which contains rogue hosts; now when your victim tries to go to a site (say google.com) they can endup where you pointed them and bob's your uncle. Thus the limitations :) – Ahmed Masud Mar 01 '17 at 19:19
-
Why do people ask this question every day. It's been asked and answered so many times... – Heretic Monkey Mar 01 '17 at 19:21
-
Possible duplicate of [Javascript: Create and save file](http://stackoverflow.com/questions/13405129/javascript-create-and-save-file) – Heretic Monkey Mar 01 '17 at 19:21
2 Answers
1
For security reasons, JavaScript isn't allowed to force a download at all, let alone to a specific location. It's not possible to do what you're asking.

Joseph Sible-Reinstate Monica
- 45,431
- 5
- 48
- 98
-
That is not totally true. You **can** create and download files using JavaScript. You just can't force where it downloads to. – spencer.sm Mar 01 '17 at 19:26
-
@spencer.sm You can't *force* a download at all. All you can do is make the browser *offer* a download. – Joseph Sible-Reinstate Monica Mar 01 '17 at 19:26
-
Responding to your comment before you edited it, I did try it and I got a download prompt. If you use Chrome and have "Ask where to save each file before downloading" turned off, then you can force a download there, but that's the exception rather than the rule. – Joseph Sible-Reinstate Monica Mar 01 '17 at 19:32
0
This is not possible. See this article for more: https://www.html5rocks.com/en/tutorials/file/filesystem/

Hum4n01d
- 1,312
- 3
- 15
- 30