How to create a meteorology app using Node.js and OpenWeatherMap API

This tuturial will show you how to create simple weather app using node.js and OpenWeatherMap API.

Step 1- Create an account on the site OpenWeatherMap.

To get start we need to acess the OpenWeatherMap website https://home.openweathermap.org/users/sign_up and register:

Then we select API Keys and it will create a key, to do this we have to insert in the name field a name that will be associated with the key that is generated.

Once created the acess Key to the API we will develop the app that wil call the API from site OpenWeatherMap.

Step2- Developing the app

If this is your first time using Node.js i suguest you to check my previous tuturials How to make your first program in Node.js and How to create a server in node.js .

The first thing to do is to create a directory with the name nodejs-weather and then we open Node.js command prompt and type the following comand (after we change the directory):

npm init

Fill the fiels with the information you want and press enter.

The output will be similar to the image below:

Output of the command npm init

Then wwe type the following command to add the packages:

npm install request — save

The we create aa Notepad++ file with the name Index.js and type the following code:

Code for the index.js file

In the line 3 we change the apiKey by the one that was generated previously on the website OpenWeatherMap.

Then on the Node.js command prompt type the following command:

node index.js

The output will look like yhis:

Output

Computer science student