Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
OscarGX committed Jun 26, 2020
0 parents commit c3a93fd
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Aplicación del clima en NodeJS utilizando OpenWeatherMap API

Ejecutar ```npm install``` para instalar los paquetes necesarios.

El API key no está incluida, pueden obtener una API key en [OpenWeather](https://openweathermap.org/) y reemplazarla
en el archivo api.js

### Ejemplo:
```
node app -d "Ciudad de Mexico"
```
18 changes: 18 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const weather = require('./weather/api');
const argv = require('yargs').options({
direccion: {
alias: 'd',
demand: true,
desc: 'Dirección de la ciudad para obtener el clima'
}
}).argv;

const loc = argv.direccion;

weather.getWeather(loc).then(data => {
if (data.data.cod == 200) {
console.log(`El clima de ${loc} es de ${data.data.main.temp}`);
}
}).catch(e => {
console.log(`Error, la ciudad no existe`);
});
227 changes: 227 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "weather--app",
"version": "1.0.0",
"description": "Aplicación del clima",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Oscar Reyes",
"license": "ISC",
"dependencies": {
"axios": "^0.19.2",
"yargs": "^15.3.1"
}
}
11 changes: 11 additions & 0 deletions weather/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const axios = require('axios').default;

const apiKey = 'your-api-key-here-xxxxxxxxxxxxxx';

const getWeather = async(city) => {
return await axios.get(`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=metric`);
}

module.exports = {
getWeather
}

0 comments on commit c3a93fd

Please sign in to comment.