A small Node.js based weather data logging application, the purpose of which is to test deployment flows for Kinsta Application Hosting. Once running, the application will log the temperature and wind speed in a given location once every minute and allow you to view the last 100 entries on a web server.
Kinsta is a developer-centric cloud host / PaaS. We’re striving to make it easier for you to share your web projects with your users. Focus on coding and building, and we’ll take care of deployment and provide fast, scalable hosting. + 24/7 expert-only support.
Get started for free, the first $20 is on us!
To be able to test multiple databases on Kinsta you can use environment variables to change the database used by the application (more on specific setup below). The following databases are supported:
- MySQL
- MariaDB
- PostgreSQL
- Redis
The app will require an API key from OpenWeatherMap. If you sign up you can grab an API key for free that should allow you to make 1,000 API calls a day. Once logged in you should be able to create a key which you'll need to use in an environment variable (see below). Note that it will take a few minutes for your new key to become active and allow requests through.
The application requires the following variables
OPENWEATHER_KEY
: The API key you generated for OpenWeatherMap servicesWEATHER_LOCATION
: A location to get weather for, for example:paris
,tokyo
. If not given the default isparis
DB_TYPE
: The type of database you'd like to use. Should be one of the following:mysql
,mariadb
,postgresql
,redis
. If not given the default ismysql
UNIT
: The unit of measurement you'd like to use.metric
for Celsius and km/h orimperial
for Fahrenheit and mi/h. If not given the default ismetric
FREQUENCY
The frequency with which to grab new weather data, 1-60 to represent every 1 minute to every 60 minutes. If not given the default is3
DB_HOST
: The hostname of your databaseDB_PORT
: The port through which the database can be accessedDB_NAME
: The name of the databaseDB_USER
: The username used to access the databaseDB_PASSWORD
: The password used to access the database
Note that if using Redis DB_NAME
and DB_USER
should not be set. In addition, Redis will only store the most recent weather data.
- Fork this repository
- Clone your forked repository locally
- Run
npm i
in the resulting folder to install dependencies - Create a file named
.env
and add the environment variables to it. Take a look at .env.example for an example. - Make sure your database is up and running, ready to accept connections
- Run
npm run setup
to create the required database table
Once everything is set up correctly you should be able to issue the following commands:
npm run getWeather
: Retrieves the latest weather data from OpenWeatherMapnpm run logWeather
: Retrieves the latest weather data and adds it to the databasenpm run listWeather
: Lists the latest 100 entries in the databasenpm run weatherLogger
: Starts a cronjob that - while running - will retreive and log the weather data every 3 minutesnpm start
: Launches a web server you can visit to view the last 100 weather data points
For a more visual description of the deployment process take a look at our Example Deployment Help Center article
- Create a new database of your choice in MyKinsta
- Create a new application and choose your cloned repository to deploy
- In the Settings page of your application click on Add Connection and select your database. Make sure to check the "Add environment variables to access the database" box. This will create all the variables starting with
DB_
for you - Go to Settings -> Environment Variables for your application and set the appropriate environment variables from above.
- At some point in this process your application deployment may have failed. This is expected behavior, it was likely caused by the environment variables not being added. If this happens a re-deploy will set things right
- Visit your deployment URL to confirm everything is working, you should see the text "Waiting for weather data"
- In the Processes section in MyKinsta click "Create a new process". Add a descriptive name (eg.: Weather logging cronjon) and use
npm run weatherLogger
as the start command - In a couple of minutes (depending on what you set as the
FREQUENCY
value) you should see weather data in a table when visiting the deployment URL