Deploy Node.js App to Fly.io

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:

  • Up to 3 shared-cpu-1x 256mb VMs
  • 3GB persistent volume storage (total)
  • 160GB outbound data transfer

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

  • Mac OS:?If you’re on a Mac OS and you have brew installed, you can use this command to install the flyctl brew install flyctl

Otherwise, there’s a script that you need to run to install it

 curl -L? https://fly.io/install.sh?| sh        

  • Linux:?For Linux users, you need to run this script

 curl -L?https://fly.io/install.sh| sh        

  • Windows:?On Windows run the Powershell install script

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.

No alt text provided for this image

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
...        

  • If you have a Dockerfile it will automatically detect it, if you don’t it will detect the Node.js app and start the deployment
  • Next, it asks for an app name, leave this empty and it will generate one
  • Choose the region where you want to deploy, whichever is closest to your users
  • It asks if you want to set up a Postgresql or Redis database — I will choose No
  • And would you like to deploy now? Yes

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.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

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.

No alt text provided for this image

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

Deploy a Node App

Log in to Fly

Install flyctl

Fly.io Pricing

Common issues with Fly.io

Troubleshooting your Deployment

?? Thanks for reading and follow for more deployment guides


#flyio #nodejs #deployment #deploynodejs #herokualternative

Chinmay Anand

SDE | Kotlin, gRPC, Java, Microservices | Working with World's Best SWE Team

1 年

I started following your posts related to devops they are amazing.

要查看或添加评论,请登录

Hayk Simonyan的更多文章

  • Beginner’s Guide to Prompt Engineering with ChatGPT

    Beginner’s Guide to Prompt Engineering with ChatGPT

    Intro Prompt Engineering is one of the highest-leverage skills that you can learn in 2023. Whether you’re developing…

  • Functional Programming Simplified

    Functional Programming Simplified

    Introduction Functional Programming revolves around the principle of separating concerns, specifically the separation…

  • REST vs GraphQL

    REST vs GraphQL

    Introduction RESTful and GraphQL APIs are two popular choices for building web APIs, each with its own strengths and…

  • React Lifecycle Methods and Their Equivalents in Functional Components

    React Lifecycle Methods and Their Equivalents in Functional Components

    React is the most popular JavaScript library for building user interfaces, and it provides a set of lifecycle methods…

    1 条评论
  • Deploying a NestJS app for Free on?Cyclic

    Deploying a NestJS app for Free on?Cyclic

    Introduction In this article, we’re going to deploy a Nestjs app for free on Cyclic Cyclic is a cloud platform that…

    1 条评论
  • Master TypeScript Interviews

    Master TypeScript Interviews

    Intro Are you preparing for a TypeScript interview and want to know what to expect? In this article, we'll go over the…

  • 7 Design Patterns You Should Know

    7 Design Patterns You Should Know

    What are Design Patterns? Design patterns are repeatable solutions to commonly occurring problems in software design…

  • What is Dependency Injection?

    What is Dependency Injection?

    Dependency Injection (DI) is a programming design pattern that makes a class independent of its dependencies. It…

  • OOP Concepts Simplified

    OOP Concepts Simplified

    Intro In this article, we’ll look at the core OOP concepts with real code examples, which will make it easier for you…

  • Deploying Your Website to Firebase

    Deploying Your Website to Firebase

    Introduction In this article, we will deploy your website frontend to Google Firebase for FREE in less than 5 minutes…

社区洞察

其他会员也浏览了