{"id":20073584,"url":"https://github.com/ragingwind/firebase-hackernews","last_synced_at":"2025-06-22T23:06:26.530Z","repository":{"id":57236616,"uuid":"91951983","full_name":"ragingwind/firebase-hackernews","owner":"ragingwind","description":"Hacker News APIs with firebase 🔥🚒🌋♨💥📛🎶🚨💽😍","archived":false,"fork":false,"pushed_at":"2017-08-08T22:31:35.000Z","size":137,"stargazers_count":23,"open_issues_count":2,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-06T08:49:55.195Z","etag":null,"topics":["firebase","hacker-news","hackernews","hackernews-api","hnpwa","pwa","pwah"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ragingwind.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-21T11:24:14.000Z","updated_at":"2025-02-18T06:56:11.000Z","dependencies_parsed_at":"2022-08-23T15:50:50.534Z","dependency_job_id":null,"html_url":"https://github.com/ragingwind/firebase-hackernews","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"purl":"pkg:github/ragingwind/firebase-hackernews","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ragingwind%2Ffirebase-hackernews","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ragingwind%2Ffirebase-hackernews/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ragingwind%2Ffirebase-hackernews/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ragingwind%2Ffirebase-hackernews/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ragingwind","download_url":"https://codeload.github.com/ragingwind/firebase-hackernews/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ragingwind%2Ffirebase-hackernews/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261380908,"owners_count":23149966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["firebase","hacker-news","hackernews","hackernews-api","hnpwa","pwa","pwah"],"created_at":"2024-11-13T14:46:52.181Z","updated_at":"2025-06-22T23:06:21.501Z","avatar_url":"https://github.com/ragingwind.png","language":"JavaScript","readme":"# firebase-hackernews\n\n\u003e Hacker News APIs with firebase\n\n## Install\n\n```\n$ npm install --save firebase-hackernews\n```\n## Test\n\n### Express\n\nRun node script at `./example/express/server.js`, or npm run express and connect to server\n\n### react\n\nThis project was generated by `create-react-app`. Navigate to `./example/react/` and then run first `npm install`, an then run `npm start`. If you have any updates before run `start`, you should reinstall the package\n\n### Service Worker\n\nTo test service worker, run `npm run sw` and connet to test server. webpack watching is default options\n\n## Usage\n\nSee [more examples](./examples) in test.js and refer to [HackerNews API](https://github.com/HackerNews/API) for more information of firebase and\n\n### Initialzing with firebase/database\n\nBecause of firebase running environment is not only for node but also browser and service worker.So you must import both of app and database from `firebase` modules before import `firebase-hackernews`.\n\n```js\nconst firebase = require('firebase');\nconst hackernews = require('firebase-hackernews');\n\n// create a service as a single instance when the fist call\n// you must pass firebase to init method\nconst hnservice = hackernews.init(firebase)\n```\n\nEven it can be running with es2015 to support for live-code importing like this below,\n\n```js\nimport firebase from 'firebase/app'\nimport from 'firebase/database'\n\nconst hnservice = hackernews.init(firebase)\n```\n\n### With Promise\n\n```js\n// get all of stories by types, 'top', 'new', 'best', 'ask', 'show', 'job'\nhnservice.stories('top').then(stories =\u003e {})\n\n// get stories with custom count and page\nhnservice.stories('top', {page: 1, count: 30}).then(stories =\u003e {})\n\n// get a user\nhnservice.user('jl').then(user =\u003e {})\n\n// get a current max item id\nhnservice.maxItem().then(update =\u003e {})\n\n// get a updated items and profiles\nhnservice.update().then(update =\u003e {})\n```\n\n### Without Promise\n\nAPIs named to xxxxCached is that support return data immediately but synchronous APIs doesn't do fetch. It only works on cached data that means asynchronous apis alreay has been called or running on watch mode\n\n```js\nhnservice.storiesCached('top').then(stories =\u003e {})\n```\n\n### Fetching with Service Worker\n\nThis module supports that running on server-worker. After initialzing in service worker, you can get a data via fetch. To do this, firstly, you must import and initialize both of firebase and hackernews service\n\n```js\n/* global importScripts hackernews */\nimportScripts('https://www.gstatic.com/firebasejs/4.1.2/firebase-app.js')\nimportScripts('https://www.gstatic.com/firebasejs/4.1.2/firebase-database.js')\nimportScripts('https://unpkg.com/firebase-hackernews@2.1.0')\n\nhackernews.init(firebase, { watch: true })\n```\n\nand then you can request a stories via fetch and subpath. see more examples in `examples/serice-worker`\n\n```js\nconst stories = await fetch('./hackernews/top')\nconst storiesRes = await stories.json()\n\nstoriesRes.data.forEach(s =\u003e {\n\t// manage a story\n})\n```\n\n## API\n\n### init(firebase, [option])\n\nReturns hackernews service powered by firebase as a single instance\n\n```\n{\n\tfirebase: `firebase package. refer to usage above`\n\toptions: {\n\t\twatch: `true / false, enable watch mode or not`\n\t\tlog: `log function, ex) console.log`\n\t}\n}\n```\n### APIs for Promise\n\n#### stories(type, [options])\n\nReturns stories with `totalLength` as an additional info after fetched and cached with options:\n\n- force: true ? returns stories fetch first, else return cached data if it exist\n- page: returns stories in page by count\n- count: count in a page. default is 50\n\n#### items(id[s], [options])\n\nReturns items by id[s] after fetched and cached with options:\n\n- force: true ? returns stories cache first, else return cached data after fetch\n\n#### user(id)\n\nReturns profile by id\n\n#### updates()\n\nReturns recent updates regardless fetched data\n\n#### maxItem()\n\nReturnes max item id of latest snapshot on firebase\n\n#### watch()\n\nMake the service keep listening on the changes of stories. It recommend to use it for desktop application and server side. refer to [the example with express.js](./examples/express)\n\n#### length(type)\n\nReturns a length of cached items of the target type\n\n#### kids(id)\n\nReturn cached all of items related to the target id. key is item's id and data will be flatted object list\n\n#### data([data])\n\nSet and get data, on cache directly. It's useful when it comes to hydrate / serialis cache\n\n### APIs for cached data\n\nCached APIs returns with data immediately from chached data without fetch and Promise. It would be possible that data is not ready befor you do calll `cached` APIs\n\n- storiesCached, identical to stories()\n- itemsCached, identical to items()\n- lengthCached, identical to length() but no promise\n- dataCached, identical to data() but no promise\n\n## License\n\nMIT © [Jimmy Moon](http://ragingwind.me)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fragingwind%2Ffirebase-hackernews","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fragingwind%2Ffirebase-hackernews","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fragingwind%2Ffirebase-hackernews/lists"}