{"id":18562493,"url":"https://github.com/replit/replit-node","last_synced_at":"2025-04-10T03:31:57.444Z","repository":{"id":40280317,"uuid":"423287735","full_name":"replit/replit-node","owner":"replit","description":"A node.js library that helps you build excellent things inside Repls!","archived":true,"fork":false,"pushed_at":"2023-10-16T14:26:59.000Z","size":33,"stargazers_count":5,"open_issues_count":1,"forks_count":4,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-08T02:16:28.155Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/replit.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":"2021-10-31T23:58:26.000Z","updated_at":"2025-02-11T18:02:07.000Z","dependencies_parsed_at":"2022-06-27T14:33:18.801Z","dependency_job_id":null,"html_url":"https://github.com/replit/replit-node","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/replit%2Freplit-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/replit%2Freplit-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/replit%2Freplit-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/replit%2Freplit-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/replit","download_url":"https://codeload.github.com/replit/replit-node/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248151096,"owners_count":21056022,"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":"2024-11-06T22:09:54.265Z","updated_at":"2025-04-10T03:31:52.425Z","avatar_url":"https://github.com/replit.png","language":"TypeScript","readme":"# replit-node\n\nA node.js library that helps you build excellent things inside Repls!\n\n## Features\n\n### Auth Middleware\n\nThe auth middleware allows for simple use of\n[Replit Auth](https://docs.replit.com/hosting/authenticating-users-repl-auth) by\ncreating a `req.auth` object with the user's `id`, `name`, and `roles`. When the user\nis not signed in, `req.auth` is `undefined`.\n\nYou can activate the middleware for you entire app like this:\n\n```js\nconst replit = require(\"PKG_NAME_TBD\");\nconst express = require(\"express\");\n\nconst app = express();\napp.use(replit.authMiddleware);\n```\n\nYou can then use the `req.auth` object in your routes:\n\n```js\napp.get(\"/\", (req, res) =\u003e {\n  // for demo purposes. it's shorter to use `requireAuth` instead of this.\n  if (req.auth) {\n    res.end(`Hello, ${req.auth.name}`);\n  } else {\n    res.send(`Sign in with Repl Auth to use this demo: ${replit.AUTH_SNIPPET}`);\n  }\n});\n```\n\n### requireAuth Middleware\n\nThe `requireAuth` middleware simplifies showing a login screen whenever the user isn't\nsigned in with Replit auth. By default, it returns the `AUTH_SNIPPET` whenever the user\nisn't signed in. For example:\n\n```js\napp.get(\"/\", replit.requireAuth(), (req, res) =\u003e\n  res.end(`Hello, ${req.auth.name}`)\n);\n```\n\nYou can also customize the login response:\n\n```js\napp.get(\n  \"/\",\n  replit.requireAuth(\n    `Sign in with Repl Auth to use this demo: ${replit.AUTH_SNIPPET}`\n  ),\n  (req, res) =\u003e res.end(`Hello, ${req.auth.name}`)\n);\n```\n\n#### Note about AUTH_SNIPPET\n\nThe auth snippet includes some JavaScript that generates a button that users can click\nto sign in to your app with Replit auth. Once they are signed in, it will reload the\npage. This means that using it will only work on pages where the user is directly\nvisiting user their browser and a GET request. It won't work with API routes. In\ncertain cases, it may make more sense to redirect users to a dedicated login page\ninstead. You can access the auth snippet by including `replit.AUTH_SNIPPET` in an HTML\nresponse (`res.send()`).\n\n### Raw Database Client\n\nFor predictable results, use the `RawClient`. It is nothing but a node interface to the\ndatabase API without any transformations or niceties. You can use it like this:\n\n```js\n// initialize it yourself\nconst db = new replit.RawClient(process.env.REPLIT_DB_URL);\n// or use the shorthand\nreplit.rawDB;\n```\n\nYou can then call the `db.list`, `db.get`, `db.setMany`, and `db.delete` functions.\n\n### Cached Database Client\n\nThe database client caches all reads and writes performed after the client was created.\nIt is not safe to use if multiple threads or processes are writing to the database at\nthe same time, as this can lead to incorrect results being returned from the cache. You\ncan use it like this:\n\n```js\nconst db = new replit.Client.create(process.env.REPLIT_DB_URL);\n// or\nreplit.db;\n```\n\nYou can use all the same methods the raw client in addition to `db.set` which uses\n`setMany` under the hood.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freplit%2Freplit-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freplit%2Freplit-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freplit%2Freplit-node/lists"}