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.

Example Application

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. If you want to use a different Git service provider, you can import the repository to Bitbucket or GitLab.

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 a fork of weatherlogger-js in GitHub.
Create a fork of weatherlogger-js in GitHub.

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.

Processes

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 npm start command.
  • A cronjob that collects weather data every few minutes. This can be started using the npm run weatherLogger command

Let’s start getting things ready to run those processes.

Create 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-central1
  • Database size: 0.25 CPU core – 256 MB RAM (Mini)

Click Create database, and you should be all set.

Creating a new database for our example application.
Creating a new database for our example application.

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

For more step-by-step documentation, see Add an Application.

We used the following values in the multipart form to create our example application:

Application details

  • GitHub repository: danielpataki/weatherlogger-js (in your case, this will be something like your-organization/weatherlogger-js)
  • Default branch: main
  • Automatic deployment on commit: unchecked
  • Application name: Weather Logger
  • Data center location: us-central1
Creating a new application for our example.
Creating a new application for our example.

Build environment

  • Build resources: Standard
  • Build environment: Set up container image automatically
Configuring the build environment for our example.
Configuring the build environment for our example.

Resources

  • Set up your processes:
    • Process name: Web process
    • Process type: web
    • Start command: npm start
    • Pod size: Standard 0.5 CPU / 1 GB RAM
    • Instance count: 1

Click Add application, and the deployment process will be started.

 

Setting up the web process for our example application.
Setting up the web process for our example application.

Payment Method

Review the example application’s monthly usage costs and confirm your payment method.

Confirming the payment method for our example application.
Confirming the payment method for our example application.

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.

Internal connections in the example application.
Internal connections in our example application.

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, select the Available during runtime and Available during build process checkboxes, and click Add connection.

Add an internal connection for our example application.
Add an internal connection for our example application.

Application Setup

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

Add your OpenWeather API Key to the environment variables.
Add your OpenWeather API Key to the environment variables.

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.

Configuring Processes

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 the web process that runs npm start we created when adding the application.

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:

Name: Worker
Type: Background job
Start command: npm run weatherLogger
Pod size: Standard 0.5 CPU / 1 GB RAM
Instances: 1

Then click Create process.

Create the background process for our example application.
Create the background process for our example application.

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.

Runtime logs for the example application.
Runtime logs for the example application.

After a couple of minutes, you should see successful processes in the Runtime logs. In the example image above, line 482 shows that the logger has started working (Starting weather logging), and line 483 shows that the web server is running (Weather server is up and running). Line 245 onwards shows logging events (Weather data retrieved and Weather data logged).

Near the top of the page, you can see your application’s URL (this can also be found on the Deployments page under Latest deployment). Click on this URL to be taken to the page being served by the web service:

Weather logger page showing weather entries.
Weather logger page showing weather entries.