{"id":20697971,"url":"https://github.com/fly-apps/fly-run-this-function-on-another-machine","last_synced_at":"2025-07-26T07:06:59.701Z","repository":{"id":173436887,"uuid":"650770755","full_name":"fly-apps/fly-run-this-function-on-another-machine","owner":"fly-apps","description":"This is a simple example on how to spawn a Fly.io machine and run a function from there.","archived":false,"fork":false,"pushed_at":"2024-02-24T00:34:59.000Z","size":760,"stargazers_count":82,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-22T21:38:13.228Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fly-apps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-06-07T19:16:09.000Z","updated_at":"2025-04-14T21:29:14.000Z","dependencies_parsed_at":"2024-02-23T22:30:06.015Z","dependency_job_id":"edc1659b-c0d3-4047-8d57-2e1d697cb786","html_url":"https://github.com/fly-apps/fly-run-this-function-on-another-machine","commit_stats":null,"previous_names":["lubien/fly-run-this-function-on-another-machine"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fly-apps/fly-run-this-function-on-another-machine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Ffly-run-this-function-on-another-machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Ffly-run-this-function-on-another-machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Ffly-run-this-function-on-another-machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Ffly-run-this-function-on-another-machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fly-apps","download_url":"https://codeload.github.com/fly-apps/fly-run-this-function-on-another-machine/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Ffly-run-this-function-on-another-machine/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267133824,"owners_count":24040785,"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","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-17T00:21:10.876Z","updated_at":"2025-07-26T07:06:59.672Z","avatar_url":"https://github.com/fly-apps.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## FLAME for JavaScript: Run a function on another Machine\n\n![Bird throwing fireballs](./javascript-flame-throwing-bird.jpg)\n\nThis is a simple example app demonstrating how to run a particular function on a temporary copy of your app, using the FLAME pattern. Checkout the blog post that explains this code in more detail: https://fly.io/javascript-journal/flame-for-javascript-rethinking-serverless\n\nFLAME (Fleeting Lambda Application for Modular Execution), which was first introduced by Chris McCord, creator of the Phoenix framework, was originally demo'ed in an Elixir library. This app is a case study on how it can be implemented in vanilla JavaScript. FLAME is a new way to horizontally auto-scale your application code in a more modular way. You can read more about it in Chris's post here: https://fly.io/blog/rethinking-serverless-with-flame/\n\n## Prerequisites\n\nWhile FLAME is a cloud-provider-agnostic pattern, this project uses Fly.io's Machines API to auto-scale your code. As such, **your app will need a [Fly token](https://fly.io/docs/flyctl/auth-token/) to be able to spawn new machines.**\n\nIf you already have the `flyctl` CLI installed, you can run the following to obtain a new token:\n\n```cmd\n$ flyctl auth token [flags]\n```\n\n## Deploying this demo\n\nFirst launch this app.\n\n```sh\n$ fly launch --copy-config --no-public-ips --no-deploy\n\nCreating app in /Users/lubien/workspace/run-this-on-another-machine\nScanning source code\nDetected a Dockerfile app\n? Choose an app name (leave blank to generate one): another-machines\n? Select Organization: Lubien (personal)\n? Choose a region for deployment: Sao Paulo, Brazil (gru)\nApp will use 'gru' region as primary\n```\n\nThe let's set the deploy token\n\n```sh\n$ fly secrets set FLY_API_TOKEN=$(fly auth token)\nSecrets are staged for the first deployment\n```\n\nMake your first deployment and remember the machine ID.\n\n```sh\n$ fly deploy\n\n...\nWatch your app at https://fly.io/apps/another-machines/monitoring\n\nUpdating existing machines in 'another-machines' with rolling strategy\n  Machine 3287114c3d7085 [app] has state: started\n  [1/1] Checking that 3287114c3d7085 [app] is up and running\n  Finished deploying\n```\n\nSSH into the main machine and run `node /app/index.mjs`\n\n```sh\n$ fly ssh console -s\n? Select VM: gru: 3287114c3d7085 fdaa:0:3335:a7b:1f60:1b01:ce26:2 muddy-violet-4491\nConnecting to fdaa:0:3335:a7b:1f60:1b01:ce26:2... complete\n\nroot@3287114c3d7085:/app# node /app/index.mjs \n```\n\nIf you look into your app Monitoring page, there will be a new machine.\n\n## Next steps:\n\n- ~~Stop machines after they're done~~\n- ~~Reuse stopped machines~~\n- Pool machines?","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffly-apps%2Ffly-run-this-function-on-another-machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffly-apps%2Ffly-run-this-function-on-another-machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffly-apps%2Ffly-run-this-function-on-another-machine/lists"}