Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@
"pages": [
"js/frameworks/astro",
"js/frameworks/deno",
"js/frameworks/farmjs",
"js/frameworks/meteor",
"js/frameworks/nextjs",
"js/frameworks/nuxtjs",
Expand Down
4 changes: 4 additions & 0 deletions js/frameworks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Each one of the language guides will take you through creating and deploying a s

* [Run an Astro App](/js/frameworks/astro/)
* [Run a Deno App](/js/frameworks/deno/)
* [Run a Farm.js App](/js/frameworks/farmjs/)
* [Run a Meteor App](/js/frameworks/meteor/)
* [Run a Next.js App](/js/frameworks/nextjs/)
* [Run a Nuxt App](/js/frameworks/nuxtjs/)
Expand All @@ -24,6 +25,9 @@ Astro is the web framework for content-driven websites.
## Run a Deno App
Deno is the open-source JavaScript runtime for the modern web.

## Run a Farm.js App
Farm.js is a full-stack framework with typed file routing, server actions, and streaming server rendering for React, Preact, Solid, Vue, and Svelte.

## Run a Meteor App
Meteor is a full-stack JavaScript framework for building modern web and mobile applications.

Expand Down
68 changes: 68 additions & 0 deletions js/frameworks/farmjs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
title: Run a Farm.js App
og:description: Farm.js is a full-stack framework with typed file routing, server actions, and streaming server rendering for React, Preact, Solid, Vue, and Svelte.
source_url: https://fly.io/docs/js/frameworks/farmjs/
---

import FlyctlSnippet from '/snippets/js/frameworks/flyctl.mdx';
import LaunchedSnippet from '/snippets/js/frameworks/launched.mdx';

Getting an application running on Fly.io is essentially working out how to package it as a deployable image. Once packaged it can be deployed to the Fly.io platform.

In this guide we'll learn how to deploy a [Farm.js](https://farmjs.dev/) application on Fly.io.

We'll be using the basic starter generated by `@farm.js/create-app`. It renders pages on the server and hydrates interactive components in the browser.

## _Deploy a Farm.js app_

We'll assume you have Node.js 22.13 or later installed and can run `npm`.

<FlyctlSnippet />

Now let's generate a new Farm.js app:

```bash
npx @farm.js/create-app@latest my-farm-app
cd my-farm-app
```

`farm build` compiles the app into a self-contained Node.js server in `.farm/.output`. Add a `Dockerfile` to the root of the app that builds it and runs that server:

```dockerfile
FROM node:22-slim AS build

WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . ./
RUN npm run build

FROM node:22-slim

WORKDIR /app
COPY --from=build /app/.farm/.output ./.farm/.output

ENV NODE_ENV=production
EXPOSE 3000
CMD ["node", ".farm/.output/server/index.mjs"]
```

And a `.dockerignore` next to it:

```
node_modules
.farm
.git
```

The runtime image only copies `.farm/.output`, which already contains the server's dependencies. If you let `fly launch` generate a Dockerfile instead, it removes development dependencies before running `npm run start`. That works when the `start` script is `node .farm/.output/server/index.mjs`, but not when it is `farm start`, because the `farm` command is a development dependency.

Now you're ready to deploy:

```bash
fly launch
```

`fly launch` uses your `Dockerfile` and sets the internal port to `3000` from its `EXPOSE` line, which is the port the Farm.js server listens on.

<LaunchedSnippet />