Functions

Write and deploy code from the Railway canvas without managing infrastructure or creating a git repository. Functions are Services that run a single file of TypeScript code using the Bun runtime. Use them like any other Service, but without the overhead of a repository.

They are ideal for small tasks like handling webhooks, cron jobs, or simple APIs.

Key features

  • Instant deploys: Deploy code changes in seconds. No need to wait for a build step.
  • Import any NPM package: Use any NPM package in your function. We will automatically install it for you when your code runs. Pin specific versions by using a package@version syntax in your imports, e.g. import { Hono } from "hono@4"
  • Use native Bun APIs: Access Bun APIs like Bun.file() and Bun.serve().
  • Service variables: Service Variables are automatically available in the function editor via import.meta.env, process.env, or Bun.env
  • Attach volumes: Persist data in your function using Volumes.
Screenshot of pre-deploy command configuration

Limitations

  • 1 file per function
  • Max file size of 96KB

Edit and Deploy

If you're familiar with VSCode or other IDEs, you'll feel right at home with our built-in editor.

  • To edit your function, open the "Source Code" tab in your service.
  • To stage your changes, press ⌘+S (or Control+S if using Windows).
  • To deploy staged changes, press Shift+Enter.

Versioning

Railway automatically versions your function code. Each time you deploy, a new version is created and is available for rollback. To rollback or redeploy a previous version, find the Deployment you want to rollback to in the "Deployments" tab of your service. Then click the "Redeploy" button.

You can find the source code of a previous deployment by opening the deployment details.

Screenshot of pre-deploy command configuration

Edit this file on GitHub