{"id":26125971,"url":"https://github.com/powersync-ja/powersync-nodejs-backend-todolist-demo","last_synced_at":"2025-06-11T06:06:50.131Z","repository":{"id":207467895,"uuid":"719306782","full_name":"powersync-ja/powersync-nodejs-backend-todolist-demo","owner":"powersync-ja","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-29T07:24:18.000Z","size":73,"stargazers_count":13,"open_issues_count":1,"forks_count":7,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-06-06T08:06:39.257Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/powersync-ja.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-11-15T22:19:23.000Z","updated_at":"2025-05-02T19:15:13.000Z","dependencies_parsed_at":"2024-05-16T12:38:59.542Z","dependency_job_id":"a9cd495b-287e-4bb2-86ad-b6ed9866c6c9","html_url":"https://github.com/powersync-ja/powersync-nodejs-backend-todolist-demo","commit_stats":null,"previous_names":["powersync-ja/powersync-nodejs-backend-todolist-demo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powersync-ja%2Fpowersync-nodejs-backend-todolist-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powersync-ja%2Fpowersync-nodejs-backend-todolist-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powersync-ja%2Fpowersync-nodejs-backend-todolist-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powersync-ja%2Fpowersync-nodejs-backend-todolist-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/powersync-ja","download_url":"https://codeload.github.com/powersync-ja/powersync-nodejs-backend-todolist-demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powersync-ja%2Fpowersync-nodejs-backend-todolist-demo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259211835,"owners_count":22822378,"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":[],"created_at":"2025-03-10T17:27:27.558Z","updated_at":"2025-06-11T06:06:50.098Z","avatar_url":"https://github.com/powersync-ja.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PowerSync Node.js Backend: Todo List Demo\n\n## Overview\n\nThis repo contains a demo Node.js server application which has HTTP endpoints to authorize a [PowerSync](https://www.powersync.com/) enabled application to sync data between a client device and a PostgreSQL or MongoDB database.\n\nThe endpoints are as follows:\n\n1. GET `/api/auth/token`\n\n   - PowerSync uses this endpoint to retrieve a JWT access token which is used for authentication.\n\n2. GET `/api/auth/keys`\n\n   - PowerSync uses this endpoint to validate the JWT returned from the endpoint above.\n\n3. PUT `/api/data`\n\n   - PowerSync uses this endpoint to sync upsert events that occurred on the client application.\n\n4. PATCH `/api/data`\n\n   - PowerSync uses this endpoint to sync update events that occurred on the client application.\n\n5. DELETE `/api/data`\n\n   - PowerSync uses this endpoint to sync delete events that occurred on the client application.\n\n## Packages\n\n[node-postgres](https://github.com/brianc/node-postgres) is used to interact with the Postgres database when a client performs requests to the `/api/data` endpoint.\n\n[mongodb](https://www.npmjs.com/package/mongodb) is used to interact with the MongoDB database when a client performs requests to the `/api/data` endpoint.\n\n[mysql2](https://www.npmjs.com/package/mysql2) is used to interact with the MySQL database when a client performs requests to the `/api/data` endpoint.\n\n[jose](https://github.com/panva/jose) is used to sign the JWT which PowerSync uses for authorization.\n\n## Requirements\n\nThis app needs a Postgres instance that's hosted. For a free version for testing/demo purposes, visit [Supabase](https://supabase.com/).\n\n## Running the app\n\n1. Clone the repository\n2. Follow the steps outlined in [PowerSync Custom Authentication Example](https://github.com/journeyapps/powersync-jwks-example) → [Generate a key-pair](https://github.com/journeyapps/powersync-jwks-example#1-generate-a-key-pair) to get the keys you need for this app. This is an easy way to get started with this demo app. You can use your own public/private keys as well. Note: This backend will generate a temporary key pair for development purposes if the keys are not present in the `.env` file. This should not be used in production.\n3. Create a new `.env` file in the root project directory and add the variables as defined in the `.env` file:\n\n```shell\ncp .env.template .env\n```\n\n4. Install dependancies\n\n```shell\nnvm use\n```\n\n```shell\npnpm install\n```\n\n## Start App\n\n1. Run the following to start the application\n\n```shell\npnpm start\n```\n\nThis will start the app on `http://127.0.0.1:PORT`, where PORT is what you specify in your `.env` file.\n\n2. Test if the app is working by opening `http://127.0.0.1:PORT/api/auth/token/` in the browser\n\n3. You should get a JSON object as the response to that request\n\n## Connecting the app with PowerSync\n\nThis process is only designed for demo/testing purposes, and is not intended for production use. You won't be using ngrok to host your application and database.\n\n1. Download and install [ngrok](https://ngrok.com/)\n2. Run the ngrok command to create a HTTPS tunnel to your local application\n\n```shell\nngrok http 8000\n```\n\nThis should create the tunnel and a new HTTPS URL should be availible e.g.\n\n```shell\nngrok by @inconshreveable                                                                                                                  (Ctrl+C to quit)\n\nSession Status                online\nAccount                       Michael Barnes (Plan: Free)\nUpdate                        update available (version 2.3.41, Ctrl-U to update)\nVersion                       2.3.40\nRegion                        United States (us)\nWeb Interface                 http://127.0.0.1:4040\nForwarding                    http://your_id.ngrok-free.app -\u003e http://localhost:8000\nForwarding                    https://your_id.ngrok-free.app -\u003e http://localhost:8000\n\nConnections                   ttl     opn     rt1     rt5     p50     p90\n                              1957    0       0.04    0.03    0.01    89.93\n```\n\n3. Open the [PowerSync Dashboard](https://powersync.journeyapps.com/) and paste the `Forwarding` URL starting with HTTPS into the Credentials tab of your PowerSync instance e.g.\n\n```\nJWKS URI\nhttps://your_id.ngrok-free.app/api/auth/keys/\n```\n\nPay special attention to the URL, it should include the `/api/auth/keys/` path as this is used by the PowerSync server to validate tokens.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowersync-ja%2Fpowersync-nodejs-backend-todolist-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpowersync-ja%2Fpowersync-nodejs-backend-todolist-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowersync-ja%2Fpowersync-nodejs-backend-todolist-demo/lists"}