/simple-from-api-to-database

Simple example api fetcher. This script make periodically requests to api and save result to database

Primary LanguageJavaScript

simple-from-api-to-database

Table of Contents

About

Simple example api fetcher app This script make periodically requests to api and save result to database

Getting Started

create collection test - (id,uid,name) with one row:
id - autogenerated,
uid - 1,
name - Rick Sanchez

Installing

git clone https://github.com/alelipona/simple-from-api-to-database.git
cd simple-from-api-to-database
npm install

create file .env with following:

POCKETBASE_HOST=https://your-pockethost-account.pockethost.io
POCKETBASE_USER=your-collection-admin-user
POCKETBASE_PASSWORD=your-collection-admin-password
API_ENDPOINT=https://rickandmortyapi.com/graphql

check if you test pocketbase collection with one row available and then:

node app.js

some from log:

  data: {
    collectionId: 'wfoh8t2zrsm3ub3',
    collectionName: 'test',
    created: '2023-03-24 13:08:44.601Z',
    id: '7mm6cxa025ozd1f',
    name: 'Abadango Cluster Princess',
    uid: 6,
    updated: '2023-03-24 13:08:44.601Z'
  }

Usage

get data from api and save