{"id":22158870,"url":"https://github.com/jlarmstrongiv/tfjs-node-lambda-helpers","last_synced_at":"2026-05-11T06:19:31.288Z","repository":{"id":44947870,"uuid":"318037251","full_name":"jlarmstrongiv/tfjs-node-lambda-helpers","owner":"jlarmstrongiv","description":"Helpers for tfjs-node-lambda","archived":false,"fork":false,"pushed_at":"2023-12-15T05:44:50.000Z","size":286,"stargazers_count":0,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T14:54:09.306Z","etag":null,"topics":["lambda","nodejs","tensorflow"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/tfjs-node-lambda-helpers","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/jlarmstrongiv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2020-12-03T01:17:56.000Z","updated_at":"2021-01-26T04:06:31.000Z","dependencies_parsed_at":"2023-12-15T06:50:23.107Z","dependency_job_id":null,"html_url":"https://github.com/jlarmstrongiv/tfjs-node-lambda-helpers","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlarmstrongiv%2Ftfjs-node-lambda-helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlarmstrongiv%2Ftfjs-node-lambda-helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlarmstrongiv%2Ftfjs-node-lambda-helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlarmstrongiv%2Ftfjs-node-lambda-helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jlarmstrongiv","download_url":"https://codeload.github.com/jlarmstrongiv/tfjs-node-lambda-helpers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245294769,"owners_count":20591900,"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":["lambda","nodejs","tensorflow"],"created_at":"2024-12-02T03:39:05.452Z","updated_at":"2026-05-11T06:19:26.266Z","avatar_url":"https://github.com/jlarmstrongiv.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tfjs-node-lambda-helpers\n\nWhen using `tfjs-node-lambda`, you have to deal with environments, release urls, releases, and timeouts. This package takes care of all of that for you.\n\n## Installation\n\n```bash\nnpm install --save --save-exact tfjs-node-lambda tfjs-node-lambda-helpers\nnpm install --save-dev --save-exact @tensorflow/tfjs-node @tensorflow/tfjs\n```\n\n\u003c!-- tfjs-node-lambda-releases --\u003e\n\n### Related libraries\n\n- [tfjs-node-lambda](https://www.npmjs.com/package/tfjs-node-lambda)\n- [tfjs-node-lambda-helpers](https://www.npmjs.com/package/tfjs-node-lambda-helpers)\n- [@tensorflow/tfjs-node](https://www.npmjs.com/package/@tensorflow/tfjs-node)\n- [@tensorflow/tfjs](https://www.npmjs.com/package/@tensorflow/tfjs)\n\n## Usage\n\nPlease note that the lambda will return a `503 SERVICE_UNAVAILABLE` error until `tf` is fully loaded to prevent errors from timing out. On the client, simply retry the request until the lambda is ready.\n\n### Tensorflow\n\n```ts\nimport type { NextApiRequest, NextApiResponse } from 'next';\nimport { PrepareTf } from 'tfjs-node-lambda-helpers';\nconst prepareTf = PrepareTf();\n\nexport default async (req: NextApiRequest, res: NextApiResponse) =\u003e {\n  const ready = await prepareTf.next();\n  if (!ready.done) {\n    return res.status(ready.value.statusCode).json(ready.value);\n  }\n  const tf = ready.value;\n\n  tf.tensor([1, 2, 3, 4]).print();\n\n  return res.status(200).json({ version: tf.version });\n};\n```\n\n### Lobe.ai\n\nIn Vercel’s dashboard, be sure `Settings \u003e Environment Variables \u003e Automatically expose System Environment Variables` is checked so that `process.env.VERCEL_URL` is not undefined.\n\n```ts\nimport type { NextApiRequest, NextApiResponse } from 'next';\nimport axios from 'axios';\nimport { PrepareLobe, isLambda, LobeModel } from 'tfjs-node-lambda-helpers';\n\nconst baseUrl = isLambda()\n  ? `https://${process.env.VERCEL_URL}`\n  : `http://localhost:3000`;\nconst prepareLobe = PrepareLobe(`${baseUrl}/static/model`);\n\nlet model: LobeModel;\n\nexport default async (req: NextApiRequest, res: NextApiResponse) =\u003e {\n  if (req.method !== 'POST') {\n    return res.status(405).json({ message: 'Method Not Allowed' });\n  }\n\n  const lobe = await prepareLobe.next();\n  if (!lobe.done) {\n    return res.status(lobe.value.statusCode).json(lobe.value);\n  } else {\n    if (!model) {\n      model = lobe.value;\n    }\n  }\n  const imageUrl = req.body.imageUrl;\n\n  const response = await axios.get(imageUrl, {\n    responseType: 'arraybuffer',\n  });\n  const results = model.predict(response.data);\n\n  return res.status(200).json({ results: results.Confidences });\n};\n```\n\n## Example\n\nCheckout a full example at [tfjs-node-lambda-example](https://github.com/jlarmstrongiv/tfjs-node-lambda-example).\n\n## Behind the scenes\n\nOur goals:\n\n- No configuration\n- Fast development experience\n- Prevent Lambda from timing out on initial load\n\nRead the [source code](https://github.com/jlarmstrongiv/tfjs-node-lambda-helpers#readme).\n\n## Contributing\n\nWe welcome contributions!\n\n†[tfjs-node-lambda-releases](https://www.npmjs.com/package/tfjs-node-lambda-releases) is soft deprecated. Due to file size limitations, 6 releases are too big to be published on npm. Use the assets on [GitHub Releases](https://github.com/jlarmstrongiv/tfjs-node-lambda/releases) instead.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlarmstrongiv%2Ftfjs-node-lambda-helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjlarmstrongiv%2Ftfjs-node-lambda-helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlarmstrongiv%2Ftfjs-node-lambda-helpers/lists"}