Você não gostaria de mover seu aplicativo para fora do ambiente de desenvolvimento local e colocá-lo em um URL acessível publicamente? Ainda assim, encontrar um serviço bom (e gratuito) para implantar seu aplicativo Node.js não é tão fácil.

Neste tutorial, veremos como implantar uma API Node.js construída com Express.js e MySQL para três serviços diferentes. Usaremos o aplicativo API para linguagens de programação que criei para minha postagem anterior em Node.js e MySQL .

Todos os serviços listados nesta postagem são totalmente gratuitos e a melhor parte é que você não precisa pegar seu cartão de crédito-não será necessário. No entanto, só um lembrete: quando não pagamos nada, haverá algumas compensações a serem feitas.

Pré-requisitos

Conforme mencionado acima, usaremos a API de linguagens de programação, que está conectada ao MySQL em freeDB.tech . Antes de continuar, no entanto, certifique-se de:

  1. Você tem uma conta GitHub e conhece os fundamentos do Git/GitHub, como bifurcar um repositório
  2. Você pode adicionar aplicativos de terceiros à sua conta GitHub para autenticação e outros fins

Vamos começar! Para prosseguir, bifurque este repositório GitHub , pois o usaremos como exemplo.

1. Qovery

Qovery se autodenomina “a maneira mais simples de implantar seus aplicativos full-stack”. Você precisará encaixar seu aplicativo Node.js para que ele seja facilmente implantado no Qovery, então vá em frente e siga este tutorial para Node.js e Docker se seu aplicativo ainda não estiver encaixado.

A IU do Qovery é intuitiva e muito útil. Começaremos registrando-se no Qovery. Vá para a página de login/inscrição e clique no botão Entrar com GitHub . Depois de autorizar o Qovery no Github, você deve estar logado no console do Qovery. Depois de fazer login, clique no botão Criar um novo projeto no canto superior esquerdo:

Quovery Criar Novo Projeto

Consequentemente, veremos a seguinte tela:

Qovery UI Criar nova tela de projeto

Selecione QoveryCommunity como a organização e digite programming-language-ap `no campo Nome do projeto . Clique em Criar e veremos a próxima tela:

Tela criada pelo projeto da comunidade Quovery

Em seguida, clique em Ir para o projeto . Você deve ver algo semelhante à página abaixo:

Linguagens de programação Qovery Api Ir para a página do projeto

Nesta página, clique em Criar um aplicativo .

Quovery Criar Aplicativo

Em seguida, clique em Tenho um aplicativo .

Qovery Connect Github Repo Programming Languages ​​

Agora selecione Conectar ao GitHub e escolha a API de linguagens de programação do repo que criamos anteriormente.

Qovery Name Application

Depois disso, verifique o nome do aplicativo (você pode alterá-lo se quiser) e clique em Avançar .

Seleção de banco de dados Qovery Tela

Na tela de seleção do banco de dados, clique em Avançar sem selecionar nenhum banco de dados, pois nosso banco de dados MySQL já está hospedado e configurado em um serviço diferente.

Quovery Programming Languages ​​API Repository

Por fim, clique em Implementar e aguarde algum tempo até que o aplicativo esteja pronto.

Aplicativo da API Quovery Programming Languages ​​criado

Em seguida, clique no botão “ Vá para o botão do projeto ”.

Qovery Go To Project Status Deploying

Aguarde mais algum tempo para que o aplicativo seja implantado. Você verá a mudança de status para executando, como abaixo:

Status de implantação do aplicativo Quovery em execução

Clique no link Abrir para ver nosso aplicativo em execução:

Open Link App Running Visual

Podemos adicionar /programming-languages ​​ ao URL para ver a lista de nossas linguagens de programação servidas pela API GET da seguinte maneira:

Lista de idiomas do programa Adicionar URL Obter Api

Ótimo! Nosso aplicativo está rodando em Qovery. Além de fácil implantação, o Qovery também oferece outros ótimos recursos, como um ambiente e URL para cada filial. Para obter mais recursos, dê uma olhada nos documentos do Qovery .

2. Vercel

Vercel , anteriormente conhecido como Zeit, atua como uma camada sobre o AWS Lambda para executar seus aplicativos. É uma plataforma sem servidor que pode executar uma variedade de coisas com um foco mais forte no front-end. Felizmente, Node.js é um dos tempos de execução oficiais no Vercel. Nossa API Express Node.js regular pode ser executada no Vercel com um arquivo vercel.json bem configurado. Vamos ver como:

Exibição da página de inscrição do Vercel

Vá para a página de inscrição do Vercel e clique em Continuar com GitHub . Depois de se autenticar, clique em Novo projeto :

Página de perfil do novo projeto Vercel

Você verá a tela abaixo:

Vercel New Project Homepage Clone Template Import Git Repository

Na lista de seus repositórios GitHub, pesquise por programação , encontre o repositório de API de linguagens de programação e clique em Importar .

Github Linguagens de Programação Api Repo Select

Consequentemente, clique em Selecionar em sua conta pessoal-observe que apenas contas pessoais são gratuitas no Vercel.

Vercel Importar Linguagens de Programação Api Project

After that click, Continue to confirm the root is the base folder, as above.

Vercel Import Project Preset Other Deploy

In the above screen, select Other as the framework and click Deploy. It will take some time to build the project:

Vercel Project Deployed Build Time

Then you will see the congratulations page to visit the deployed project:

Vercel Congratulations Page Deployed

When you click Visit, you’ll see something like the below:

Vercel Visit Message Ok

To check the database connection, we can add /programming-languages to view the following output:

Database Connection Check Add Programming Languages

Hurray! Our app is running on Vercel now. Please be careful of the vercel.json file in the repo — that config is required for Vercel to run the Node.js build for our project.

3. Heroku

Heroku is a pioneer in the platform-as-a-service market. It started out as a Ruby deployment service and has expanded to support languages like Node.js, Python, and PHP, to name a few.

Let’s proceed to deploy our application to Heroku. First, you will need to sign up:

Heroku Create Free Account

Then log in to Heroku.

Heroku Log In Personal Account

On the dashboard page, click on New and then Create new app, as above.

Heroku Create New App Name

After that, type in a name for the app, like programming-languages-api in the above case. You might need to type in something different and available. Consequently, hit the “Create app” button.

Heroku Github Connect Programming Languages Repo

On the above screen, click GitHub and select Connect beside the programming-languages-api repo you had forked in the first step.

Heroku Connect Github Repository

After that, scroll down and click Deploy Branch for the master branch.

Heroku Deploy Branch Master Branch

We will see the build, deployment logs, and a success message, like below:

Heroku Build Deployment Logs Success Message

Click on View to see an output like below:

Heroku View Output Message Ok

Next, we can add /programming-languages to the URL to see that the app is able to connect to the database and render the rows correctly:

Heroku View Output Message Okk

Yay! Our app is working fine on Heroku, too. Another tip is to turn on the Enable Automatic Deploys for your master/main branch. This means each change to the main branch will be automatically deployed.

You can find the Enable Automatic Deploy button above the Manual deploy section, as seen below:

Automatic Deploys Github

One issue with the Heroku free plan is that the dyno sleeps after 30 minutes of inactivity. A workaround is to use Kaffeine to keep your apps awake even after 30 minutes of no requests hitting it.

Other options to consider

Those were the three amazing services that let us deploy a Node.js application for no cost at all, with no need to enter our credit card number. Of course, there are other services with which you could potentially run your Node.js app for no cost, but you will need to enter your billing information.

Here are some options I have tried:

  • Google Cloud Run: part of the Google Cloud platform that runs serverless containers. You could get up to 2 million requests per month for free
  • Fly.io: a CDN-as-backend kind of concept. Deploy your app servers close to your users. You could run three small VMs for free
  • Openode.io: free only for open source projects. but the most affordable plan is $0.75 per month with 50 MB memory

If you are comfortable putting down your credit card, any of the above options work in a pinch.

Conclusão

All the above free services have a command line tool, too. If you are more comfortable with the CLI, you can give that a try as well.

The next good step would be to try mapping custom domains to your apps where applicable. It would be good to look at deployment logs and application logs on the mentioned services.

Till next time, happy deploying!

The post 3 services to deploy your Node.js app for free appeared first on LogRocket Blog.

Source link