In this guide, we’ll go through the steps to deploy an example application and database. Feel free to use the example application below for testing, but please do not rely on it for any sort of production use. The purpose of the application is to test Kinsta deployment.
Prefer to watch the video version?
We have created a small application to log the weather and display the results on a simple page. You can find the application on GitHub.
Fork the Example Application
First, visit the application weatherlogger-js on GitHub and read the included Readme file to learn about the application. Once you’ve familiarized yourself with it, click on the Fork button in the top right to fork it to your own GitHub account.
Create an API Key
The app requires an API key from OpenWeather. Once you sign up, you can log in and create an API key for free that allows you to make 1,000 API calls daily. We recommend doing this step first as it takes the API key 10-20 minutes to become active, which we can spend setting up our application.
When deploying the application to Kinsta, we need to run two processes:
- A web server where we can view our weather data. This can be started using the
- A cronjob that collects weather data every few minutes. This can be started using the
npm run weatherLoggercommand
Let’s start getting things ready to run those processes.
Deploy a Database
In MyKinsta, make sure you’re on the Applications page, click Add service, then select Database in the dropdown menu. We used the following values in the form to create our example database:
- Database name: weatherloggerdb
- Display name: Weather Logger Database
- Database type: MySQL
- Version: 8.0
- We left the Database username and password untouched
- Data center location: us-east4-a
- Database size: 2 CPU cores – 512 MB RAM (Mini)
Click the Create database button, and you should be all set.
Deploy an Application
Make sure you’re on the Applications page, click Add service, then select Application in the dropdown menu. When clicking on the GitHub repository field, you’ll need to allow Kinsta to interact with your repository.
We used the following values in the form to create our example application:
- GitHub repository:
danielpataki/weatherlogger-js(in your case, this will be something like
- Default branch: main
- Automatic deployment on commit: unchecked
- Build environment: Set up container image automatically
- Application name: Weather Logger
- Data center location: us-east4-a
Click Add application, and the deployment process will be started.
Connecting the Application and Database
Once the database is ready for connections (a green check mark is shown next to it), we can hook it up to our application, even if the application is still deploying. Click the Weather Logger application, click Settings in the sidebar, and scroll down to find the Internal connections section.
Click on Add connection, and in the modal/pop-up window that appears, select the Weather Logger Database. Select the Add environment variables to access the database checkbox, scroll to the bottom of the window and click Add connection.
The next thing on our list is to add all the information that our application needs in the form of environment variables. Most of the information was automatically added in the previous step by populating the database connection variables.
The only one missing that is required by the application is the OpenWeatherMap API key. In the Settings, just under the Internal connections section, you’ll see the Environment variables section. Click Add environment variable and use
OPENWEATHER_KEY as the key and your API key as the value.
The application supports a few more variables for controlling update frequency, units used, etc. Take a look at the application’s documentation for more information.
We mentioned in the beginning that we’ll need a web server and a cronjob. Head over to the Processes section of the application, and you’ll see that a web process is created automatically and runs
npm start by default which is exactly what we need.
To set up the cronjob, click the Create process button and fill out the form in the modal/pop-up that appears. We used the following values for our example:
Type: Background job
npm run weatherLogger
Pod size: nano
Then click the Create process button.
Deploy the Application
Finally, head back to the Deployments section and click the Deploy now button. The deployment usually takes about 90 seconds, but you may need to wait a little longer for all processes to kick in properly. Your first weather measurement should be logged a few minutes after that. To check that everything is working, take a look at the Logs section.
After a couple of minutes, you should see successful processes in the Runtime logs. In the example image above, line 243 shows that the logger has started working (
Starting weather logging), and line 244 shows that the web server is running (
Weather server is up and running). Line 245 onwards shows two logging events (
Weather data retrieved).
If you head back to the Deployments section, you should see the Latest deployment URL. Click on this URL to be taken to the page being served by the web service: