Deploy Node.js App to Fly.io
Introduction
In this article, we’re going to deploy a Node.js application to?Fly.io?in 3 easy steps. Fly.io is a Hosting Platform very similar to Heroku and it is very easy to deploy an app using their CLI.
They have free allowances and if your app doesn’t exceed these limits that you see here you can use their services for free.
Free Allowances
Resources included for free on all plans:
Step 1: Install flyctl
Open up the application which you want to deploy, if you just want to follow along, here’s my?simple Node.js app?for demonstrating the deployment.
The first thing we need to do for deploying our app is to?install the flyctl, it’s a CLI for managing apps on Fly.io
Otherwise, there’s a script that you need to run to install it
curl -L? https://fly.io/install.sh?| sh
curl -L?https://fly.io/install.sh| sh
iwr? https://fly.io/install.ps1?-useb | iex
Step 2: Signup/Login to Fly
The next step is to sign up or log in to Fly.io. If you already have an account use this command to log in from the terminal
flyctl auth login
Otherwise use the signup command to signup and login
flyctl auth signup
I don’t have an account yet so I will use the signup command to open one. Type?flyctl auth signup?in your terminal and use GitHub for signing up.
Once you sign up, it will ask you for card details, although you can choose to try it for free without providing a credit card it will be required for deploying your app so it is better to provide a credit card here. It won’t charge you at all if you don’t exceed their free allowance limits.
Step 3: Deploy
After you signed up and provided card info or logged in if you had an account already the last step is to deploy your app using flyctl CLI.
领英推荐
Before you do that,?you have to set your internal port to 8080?because it is set to 8080 in the?fly.toml?file generated by the CLI
So update the port to 8080 and run the deploy command.
flyctl launchScanning source code
Detected a Dockerfile app
? Choose an app name (leave blank to generate one):
? Choose a region for deployment: > Miami, Florida (US) (mia)
? Would you like to set up a Postgresql database now? No
? Would you like to set up an Upstash Redis database now? No
? Would you like to deploy now? YesDeploying
...
1 desired, 1 placed, 1 healthy, 0 unhealthy [health checks: 1 total, 1 passing]
--> v1 deployed successfully
Verifying the deployment
To verify that it worked, go to your dashboard. Select the app that you just deployed and open up the link provided under Hostname.
And our application is successfully up and running
Also, you might have environmental variables in your code, these can be added here under the secrets tab in your dashboard.
Summary
That’s all it takes to deploy your app to Fly.io, for more complex apps it might require some additional steps, but the process is the same and you can already start deploying using this guide.
Resources
?? Thanks for reading and follow for more deployment guides
SDE | Kotlin, gRPC, Java, Microservices | Working with World's Best SWE Team
1 年I started following your posts related to devops they are amazing.