1

I made one Dyno app in Heroku using node.js

that Dyno task is to collect data and create json file daily

but I don't know how to download them locally

I tried

http://myappname.heroku.com/filename.json

but failed

Heroku is new for me,so please don't treat me like advance user

Isoftmaster
  • 3,175
  • 2
  • 11
  • 15

2 Answers2

-1

You cannot do this.

If your code is writing a JSON file to the Heroku server daily, that file is almost instantly being deleted, so there is no way you can download it.

Heroku dynos are ephemeral. This means that any data you 'save' to the filesystem will be deleted almost instantly. If you need to save files, you should save them to a file service like Amazon S3 -- then download them through there.

rdegges
  • 32,786
  • 20
  • 85
  • 109
  • can you please tell me how i am using `fs.writeFile("myfile.json", json)` this line for writing files or if possible can i save in google drive please tell me that code also – Isoftmaster May 04 '16 at 01:12
  • `almost instantly being deleted` is incorrect. `During the dyno’s lifetime its running processes can use the filesystem as a temporary scratchpad, but no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted. ` – Rahat Mahbub May 06 '16 at 05:46
  • It should suffice in this case. – Rahat Mahbub May 06 '16 at 05:46
  • 1
    Dynos restart VERY FREQUENTLY. You should be incredibly careful to do this. Generating a file every few hours is not a reliable way to do what this guy is trying to do. This is very bad advice. If you need the file to exist, USE A PROPER FILE STORE!! – rdegges May 06 '16 at 22:26
-2

Save your JSON file to /public folder.

Ensure that your app.js has the following: app.use(express.static(__dirname + '/public'))

Now, you should be able to access: http://myappname.heroku.com/filename.json

Rahat Mahbub
  • 2,967
  • 17
  • 29
  • my app name is findapp912 , so i will use `findapp912.use(express.static(__dirname + '/public'))` at top of my code? and i am using `fs.writeFile("myfile.json", json)' to write file where i should specify the `/public` folder. – Isoftmaster May 03 '16 at 07:55
  • Nope. You keep `app.use` – Rahat Mahbub May 06 '16 at 05:44
  • Use `fs.writeFile("public/myfile.json", json)'` – Rahat Mahbub May 06 '16 at 05:45
  • 1
    If anyone is visiting this thread in the future, please don't do this. Dynos restart very frequently, and the files will likely be deleted before you try to download them. This is a very unreliable way of storing files, and should not be done if you are trying to download files in a reliable way. – rdegges May 06 '16 at 22:27