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.
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.
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.
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:
- GitHub repository:
danielpataki/weatherlogger-js(in your case, this will be something like
- Default branch: main
- Automatic deployment on commit: unchecked
- Application name: Weather Logger
- Data center location: us-central1
- Build resources: Standard
- Build environment: Set up container image automatically
- Set up your processes:
- Process name: Web process
- Process type: web
- Start command:
- Pod size: Standard 0.5 CPU / 1 GB RAM
- Instance count: 1
Click Add application, and the deployment process will be started.
Review the example application’s monthly usage costs and confirm your payment method.
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, select the Available during runtime and Available during build process checkboxes, 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 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 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:
Type: Background job
npm run weatherLogger
Pod size: Standard 0.5 CPU / 1 GB RAM
Then click Create process.
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 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: