My issue is simple on paper - I have a React Native project and I'm trying to make a script that will run on build and fetch JSON from a URL, then save it as JSON file with a custom name inside a specified path/folder. For example, I want to access the JSON at www.example.com
and save it as a JSON file in project/src/assets/locales/en.json
The problem is that when I google how to fetch and save JSON, most of the results are related to Node.js and I don't think I can use them. Is what I'm trying to do possible?
CodePudding user response:
Since you've said you're doing this in a git
push hook, you can use any of several things for this:
You can indeed use Node.js, by having the hook run it via
node
, and then using Node.js'shttp
client (to read it) andfs
module (to write it to a file).You can use a shell script, perhaps using with
curl
orwget
(on platforms where those are available).
Since you're already writing JavaScript code for the app itself, Node.js is a reasonable choice.