@mugan86/openweather-api
Version:
Openweather Api Project in Node Typescript
125 lines (100 loc) • 3.65 kB
Markdown
[](https://badge.fury.io/js/%40mugan86%2Fopenweather-api)
[](https://travis-ci.org/npm-js-ts-angular-modules-course/training-node-ts-openweather-api)
[](https://coveralls.io/github/npm-js-ts-angular-modules-course/training-node-ts-openweather-api?branch=master)
[](https://github.com/npm-js-ts-angular-modules-course/training-node-ts-openweather-api)
API Openweather with basic request.
* By city name: Examples = ('Roma,it', 'Barcelona,es', 'Paris,fr', 'Bilbao,es' ,...)
* By location: Example: {lat: 36.1699412, lng: -115.13982959999998} = Las Vegas
* By zip code: Example: 89104 - Las Vegas
* Pending to implement
```
npm install @mugan86/openweather-api
```
```
npm run watch
```
or
```
tsc -w
```
* Register in Openweathermap.
* Take API key from: [API Keys](https://home.openweathermap.org/api_keys)
* Follow this example. Basic example.
Typescript
```typescript
import { ApiService } from '@mugan86/openweather-api';
const api = new ApiService('YOUR_API_KEY', 'm', 'es');
```
Javascript
```javascript
const lib = require('@mugan86/openweather-api');
const apiService = lib.ApiService;
const api = new apiService('YOUR_API_KEY'); // unit metric = metres / lang = english
```
```javascript
api.getCurrentWeather('city', ['Barcelona,es']).then(
(data) => {
console.log('***************** BARCELONA *****************');
console.log(data)
},
(err) => console.error(err) // Show error in console);
);
api.getCurrentWeather('zip', ['89104']).then(
(data) => {
console.log('***************** LAS VEGAS *****************');
console.log(data)
},
(err) => console.error(err) // Show error in console);
);
api.getCurrentWeather('location', [{lat: 36.1699412, lon: -115.13982959999998}]).then(
(data) => {
console.log('***************** LAS VEGAS *****************');
console.log(data)
},
(err) => console.error(err) // Show error in console);
);
```
If you want to include this library inside a project builds with `webpack` for a `client` application, you must add this configuration inside your `webpack configuration`:
```javascript
{
target: "web",
node: {
fs: "empty",
net: "empty",
tls: "empty"
}
}
```
If you want to include this library inside a project builds with `webpack` for a `client` application, you must add this configuration inside your `webpack configuration`. Go to **node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js**
Go to file end and replace:
```javascript
{
plugins: extraPlugins,
node: false
}
```
with
```javascript
{
plugins: extraPlugins,
target: "web",
node: {
fs: "empty",
net: "empty",
tls: "empty"
}
}
```
[](https://choosealicense.com/licenses/mit/)