Deploying an ElysiaJS App
ElysiaJS is a fast, modern, and lightweight web framework for Node.js, designed for building scalable APIs and web applications with minimal overhead. It features a simple API, TypeScript support, and a focus on performance, making it ideal for both small projects and large-scale services.
This guide explains how to deploy an ElysiaJS application to Klutch.sh, both with and without a Dockerfile. It also covers installation and provides sample code to get started.
Prerequisites
- Node.js 18+
- Git and GitHub account
- Klutch.sh account
Getting Started: Install ElysiaJS
- Create a new directory for your app and initialize npm:
Terminal window mkdir my-elysia-appcd my-elysia-appnpm init -y - Install ElysiaJS:
Terminal window npm install elysia - Create a basic ElysiaJS app (
index.js
):import { Elysia } from 'elysia';const port = process.env.PORT || 3000;new Elysia().get('/', () => 'Hello from ElysiaJS on Klutch.sh!').listen(port);console.log(`Server running on port ${port}`); - Add a start script in your
package.json
:"scripts": {"start": "node index.js"} - Test locally:
Visit http://localhost:3000 to see your app running.
Terminal window npm start
Deploying Without a Dockerfile
- Push your ElysiaJS app to a GitHub repository.
- Log in to Klutch.sh.
- Create a new project and give it a name.
- Create a new app:
- Select your ElysiaJS GitHub repository and branch
- Set the port to route traffic (usually 3000 for ElysiaJS)
- Choose region, compute, number of instances, and add any environment variables
- Add a start script in your
package.json
as shown above. - Click “Create” to deploy. Klutch.sh will build and deploy your app automatically.
Deploying With a Dockerfile
- Add a
Dockerfile
to your project root. Example:# Use official Node.js imageFROM node:18-alpine# Set working directoryWORKDIR /app# Copy package files and install dependenciesCOPY package*.json ./RUN npm install --production# Copy app sourceCOPY . .# Expose port (match your ElysiaJS app)EXPOSE 3000# Start the appCMD ["npm", "start"] - Push your code (with Dockerfile) to GitHub.
- In Klutch.sh, follow the same steps to create a project and app, but select the Dockerfile option when prompted.
- Set the service details and environment variables as needed.
- Click “Create” to deploy. Klutch.sh will build your Docker image and deploy your app.
Note: Your ElysiaJS app should always listen on the PORT
environment variable as shown above.
Resources
Deploying to Klutch.sh is simple and flexible. Choose the method that best fits your workflow and project requirements.