NodeJS server app for fetching JSON files from a Google Cloud Storage API and inserting it into PostgreSQL with repeated intervals.
The app assumes that there are existing tables in PostgreSQL with the same names as the files being downloaded, and whose table schemas map perfectly to the data structures in the JSON files.
The minimum requirements are:
- Git
- Node.js (version 4 or higher is recommended)
- To get your own local copy of gcs2postgresql use git to clone the repository with the command below:
git clone https://github.com/haninge-geodata/gcs2postgresql.git
- To install the required node dependencies run the following command from the root directory of origo-server:
npm install
- Acquire a JSON key file.
- Generate a service account: The Google Cloud Storage Console can be used to create a service account in "APIs & Services --> Credentials". This can be created on the account of the API owner and provided to you, or you can create it on your own account.
- Find the Service account details (e g by clicking on the service account in Credentials), go to the KEYS tab and choose ADD KEY --> Create new key.
- Store the key file somewhere safe and put a copy somewhere accessible to gcs2postgresql.
- Update the config.json file with your specific details
- The name of the Google Cloud Storage Bucket
- The list of JSON files to download
- Filename
- An array of columns/attributes on each JSON object in the file
- What scheduling interval to use, see the
node-cron
docs for syntax tips. - Whether to append data to the target tables (true) or clear the tables before each download.
- The path to the key file from step 3 above.
- The connection details for your target PostgreSQL server.
- To start gcs2postgresql, run:
node gcs2postgresql.js
gcs2postgresql can be installed as a Windows service. Complete steps 1-5 above, then run the following command from tasks:
node create_windowsservice.js
To uninstall run the following command from tasks:
node uninstall_windowsservice.js