Automate and configure your apps & servers using Clever Cloud ⚡️

In the #week3-day2 at MentorLéo, we used a database with our Node.js app to store stuff 💻

Today is day 3 of week 3. Easy day.

We’ll just bring what you’ve done online 💪

Requirements: read & understand this article about Git & Github.

Firebase is fine to serve static stuff (html, css, javascript). But we can’t use it to host and monitor a backend app running all the time (our Node.js app).

There are many products to help you manage your servers. I chose to use Clever Cloud because I trust the product and the team 😉

Step 1: Create an account on Clever Cloud

You’ll have some free credits, enough for several months of non-stop service. You use them by putting apps online. You can make your app online to test it, then stop it. You’ll spend no credits if nothing is running !

Step 2: Configure an app

You have to choose an instance size (quantity of RAM + CPU). Each have a specific price / month.

For this app use the smallest instance 😉

Step 3: Make your first deploy

In the information panel of your Node.js application, you’ll see instructions to deploy your app. Do that command to associate clever cloud to your local git repository (read the article above again about Git if needed):

git remote add clever git+ssh://{}.git

And then deploy the master branch on the “clever” remote you created just before 😎

git push clever master

This will install your Node.js dependencies, build your app and make it available online.

Get the url of your app in the top right corner of the overview tab, and try your /hello route to see if it works !

The logs of your app are available in the “logs” tab. Easy.

If you try other routes like /insert, you’ll see that we can’t use the database for now. We need to configure it.

Step 4: Configure a MongoDB

Just add a “MongoDB” addon in CleverCloud, choose the free plan. No configuration needed 😂

Step 5: Use environment variables

As developers we often use environment variables to specify a configuration that depends on the environment.

In our case, we want to talk to the database in local (on the laptop) and in production (on Clever Cloud). But we don’t want to hardcode the parameters. If the configuration changes, we just want to change the environment variables (remember: a good developer is lazy).

CleverCloud is clever, they already injected the correct environment variables in your app when you added the MongoDB.

It’s time to modify your code !

Note that I used a ternary operator that behaves like this:

condition ? do-this-if-true : do-that-if-false

Basically it’s a condensed if / else. But damned this is handy.

Commit your work using git, and deploy:

git push clever master

Note that by pushing on the “clever” remote, you don’t save your work on your “origin” remote (on github/gitlab/bitbucket/etc). I advize you to push there aswell when you’ve tested your work on CleverCloud.

Congrats everything should be online !

Next day we’ll assemble all the bricks together 😍

→ click here to go to Day 4 👍

Call to action

Join us and get help from professional mentors !

Apply here, it will always be free ♥