Home

Awesome

feathers-openweathermap

npm GitHub Workflow Status Code Climate maintainability Code Climate coverage David npm GitHub license

Ever needed weather information in your feathers.js app? No matter if historical, current or forecast data. This is thin layer around the OpenWeatherMap API wrapped in a feathers.js service.

Supported APIs

Installation

npm install feathers-openweathermap

Get your appid

Follow the instructions at: https://openweathermap.org/appid

Creating a service

const { Service } = require('feathers-openweathermap');

app.use("/weather", new Service({
  appid: "YOUR_APP_ID",
}))

Service options

Methods

The service exposes two standard methods, find(params) and create(data, params) and custom methods for @feathersjs/feathers@5. These methods are functionally equivalent. The create() method is added so that you can take advantage of the .on('created') service event.

When using the find(params) method, include the query as the params to be passed to the underlying OpenWeatherMap method.

find(params)

Current weather

// by city name https://openweathermap.org/current#name
app.service('weather').find({ 
  query: { 
    endpoint: 'weather', 
    cityName: "Munich", 
    stateCode: "DE"
  }
});

// by city id https://openweathermap.org/current#cityid
app.service('weather').find({ 
  query: { 
    endpoint: 'weather', 
    cityId: 2844588 
  } 
});

// by geo coordinates https://openweathermap.org/current#geo
app.service('weather').find({ 
  query: { 
    endpoint: 'weather', 
    lat: 52.520008
    lon: 13.404954
  } 
});

// by zip code https://openweathermap.org/current#zip
app.service('weather').find({ 
  query: { 
    endpoint: 'weather', 
    zipCode: "18057", 
    countryCode: "DE"
  } 
});

Onecall

app.service('weather').find({ 
  query: { 
    endpoint: 'onecall', 
    lat: 52.520008, 
    lon: 13.404954
  } 
});

Forecast

// by city name https://openweathermap.org/forecast5#name5
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast', 
    cityName: "Munich", 
    stateCode: "DE"
  }
});

// by city id https://openweathermap.org/forecast5#cityid5
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast', 
    cityId: 2844588 
  } 
});

// by geo coordinates https://openweathermap.org/forecast5#geo5
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast', 
    lat: 52.520008,
    lon: 13.404954
  } 
});

// by zip code https://openweathermap.org/forecast5#zip
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast', 
    zipCode: "18057", 
    countryCode: "DE"
  } 
});

Hourly forecast

// by city name https://openweathermap.org/api/hourly-forecast#name5
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/hourly', 
    cityName: "Munich", 
    stateCode: "DE"
  }
});

// by city id https://openweathermap.org/api/hourly-forecast#cityid5
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/hourly', 
    cityId: 2844588 
  } 
});

// by geo coordinates https://openweathermap.org/api/hourly-forecast#geo5
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/hourly', 
    lat: 52.520008,
    lon: 13.404954
  } 
});

// by zip code https://openweathermap.org/api/hourly-forecast#zip
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/hourly', 
    zipCode: "18057", 
    countryCode: "DE"
  } 
});

Daily forecast

// by city name https://openweathermap.org/forecast16#name16
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/daily', 
    cityName: "Munich", 
    stateCode: "DE"
  }
});

// by city id https://openweathermap.org/forecast16#cityid16
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/daily', 
    cityId: 2844588 
  } 
});

// by geo coordinates https://openweathermap.org/forecast16#geo16
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/daily', 
    lat: 52.520008,
    lon: 13.404954
  } 
});

// by zip code https://openweathermap.org/forecast16#zip
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/daily', 
    zipCode: "18057", 
    countryCode: "DE"
  } 
});

Climatic forecast

// by city name https://openweathermap.org/api/forecast30#name-year
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/climatic', 
    cityName: "Munich", 
    stateCode: "DE"
  }
});

// by city id https://openweathermap.org/api/forecast30#cityid-year
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/climatic', 
    cityId: 2844588 
  } 
});

// by geo coordinates https://openweathermap.org/api/forecast30#geo-year
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/climatic', 
    lat: 52.520008,
    lon: 13.404954
  } 
});

// by zip code https://openweathermap.org/api/forecast30#zip-year
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/climatic', 
    zipCode: "18057", 
    countryCode: "DE"
  } 
});

Air pollution

// current air pollution https://openweathermap.org/api/air-pollution#current
app.service('weather').find({ 
  query: { 
    endpoint: "air_pollution", 
    lat: 52.520008, 
    lon: 13.404954 
  } 
});

// forecast air pollution https://openweathermap.org/api/air-pollution#current
app.service('weather').find({ 
  query: { 
    endpoint: "air_pollution/forecast", 
    lat: 52.520008, 
    lon: 13.404954 
  } 
});

// historical air pollution https://openweathermap.org/api/air-pollution#history
app.service('weather').find({ 
  query: { 
    endpoint: "air_pollution/history", 
    start: 1606223802, 
    end: 1606482999, 
    lat: 52.520008, 
    lon: 13.404954
  } 
});

create(data)

Current weather

// by city name https://openweathermap.org/current#name
app.service('weather').create({ 
  endpoint: 'weather', 
  cityName: "Munich", 
  stateCode: "DE"
});

// by city id https://openweathermap.org/current#cityid
app.service('weather').create({ 
  endpoint: 'weather',
  cityId: 2844588
});

// by geo coordinates https://openweathermap.org/current#geo
app.service('weather').create({ 
  endpoint: 'weather', 
  lat: 52.520008,
  lon: 13.404954
});

// by zip code https://openweathermap.org/current#zip
app.service('weather').create({ 
  endpoint: 'weather', 
  zipCode: "18057", 
  countryCode: "DE"
});

Onecall

app.service('weather').create({ 
  endpoint: 'onecall', 
  lat: 52.520008, 
  lon: 13.404954
});

Forecast

// by city name https://openweathermap.org/forecast5#name5
app.service('weather').create({ 
  endpoint: 'forecast', 
  cityName: "Munich", 
  stateCode: "DE"
});

// by city id https://openweathermap.org/forecast5#cityid5
app.service('weather').create({ 
  endpoint: 'forecast', 
  cityId: 2844588 
});

// by geo coordinates https://openweathermap.org/forecast5#geo5
app.service('weather').create({ 
  endpoint: 'forecast', 
  lat: 52.520008,
  lon: 13.404954 
});

// by zip code https://openweathermap.org/forecast5#zip
app.service('weather').create({ 
  endpoint: 'forecast', 
  zipCode: "18057", 
  countryCode: "DE" 
});

Hourly forecast

// by city name https://openweathermap.org/api/hourly-forecast#name5
app.service('weather').create({ 
  endpoint: 'forecast/hourly', 
  cityName: "Munich", 
  stateCode: "DE"
});

// by city id https://openweathermap.org/api/hourly-forecast#cityid5
app.service('weather').create({ 
  endpoint: 'forecast/hourly', 
  cityId: 2844588  
});

// by geo coordinates https://openweathermap.org/api/hourly-forecast#geo5
app.service('weather').create({ 
  endpoint: 'forecast/hourly', 
  lat: 52.520008,
  lon: 13.404954 
});

// by zip code https://openweathermap.org/api/hourly-forecast#zip
app.service('weather').create({ 
  endpoint: 'forecast/hourly', 
  zipCode: "18057", 
  countryCode: "DE" 
});

Daily forecast

// by city name https://openweathermap.org/forecast16#name16
app.service('weather').create({ 
  endpoint: 'forecast/daily', 
  cityName: "Munich", 
  stateCode: "DE"
});

// by city id https://openweathermap.org/forecast16#cityid16
app.service('weather').create({ 
  endpoint: 'forecast/daily', 
  cityId: 2844588 
});

// by geo coordinates https://openweathermap.org/forecast16#geo16
app.service('weather').create({ 
  endpoint: 'forecast/daily', 
  lat: 52.520008,
  lon: 13.404954 
});

// by zip code https://openweathermap.org/forecast16#zip
app.service('weather').create({ 
  endpoint: 'forecast/daily', 
  zipCode: "18057", 
  countryCode: "DE" 
});

Climatic forecast

// by city name https://openweathermap.org/api/forecast30#name-year
app.service('weather').create({ 
  endpoint: 'forecast/climatic', 
  cityName: "Munich", 
  stateCode: "DE"
});

// by city id https://openweathermap.org/api/forecast30#cityid-year
app.service('weather').create({ 
  endpoint: 'forecast/climatic', 
  cityId: 2844588 
});

// by geo coordinates https://openweathermap.org/api/forecast30#geo-year
app.service('weather').create({ 
  endpoint: 'forecast/climatic', 
  lat: 52.520008
  lon: 13.404954 
});

// by zip code https://openweathermap.org/api/forecast30#zip-year
app.service('weather').create({ 
  endpoint: 'forecast/climatic', 
  zipCode: "18057", 
  countryCode: "DE" 
});

Air pollution

// current air pollution https://openweathermap.org/api/air-pollution#current
app.service('weather').create({ 
  endpoint: "air_pollution",
  lat: 52.520008,
  lon: 13.404954
});

// forecast air pollution https://openweathermap.org/api/air-pollution#current
app.service('weather').create({ 
  endpoint: "air_pollution/forecast",
  lat: 52.520008,
  lon: 13.404954
});

// historical air pollution https://openweathermap.org/api/air-pollution#history
app.service('weather').create({
    endpoint: "air_pollution/history",
    start: 1606223802,
    end: 1606482999,
    lat: 52.520008,
    lon: 13.404954
});

currentWeatherData(data)

app.service('weather').currentWeatherData({ 
  cityId: 2844588
});

oneCall(data)

app.service('weather').oneCall({
  lat: 52.520008,
  lon: 13.404954
});

fiveDay3HourForecast(data)

app.service('weather').fiveDay3HourForecast({
  cityName: "Munich", 
  stateCode: "DE", 
  countryCode: "DE"
})

hourlyForecast4Days(data)

app.service('weather').hourlyForecast4Days({
  cityName: "Munich", 
  stateCode: "DE", 
  countryCode: "DE"
})

dailyForecast16Days(data)

app.service('weather').dailyForecast16Days({
  cityName: "Munich", 
  stateCode: "DE", 
  countryCode: "DE"
})

climaticForecast30Days(data)

app.service('weather').climaticForecast30Days({
  cityName: "Munich", 
  stateCode: "DE", 
  countryCode: "DE"
})

airPollutionCurrent(data)

app.service('weather').airPollutionCurrent({ 
  lat: 52.520008, 
  lon: 13.404954 
});

airPollutionForecast(data)

app.service('weather').airPollutionForecast({ 
  lat: 52.520008, 
  lon: 13.404954 
});

airPollutionHistorical(data)

app.service('weather').airPollutionCurrent({ 
  lat: 52.520008, 
  lon: 13.404954,
  start: 1606223802, 
  end: 1606482999
});

Testing

Simply run npm test and all your tests in the test/ directory will be run. This project is setup with vscode. You can use the debugger with breakpoints. To run tests locally, you'll need your own appid. You can get it here: https://openweathermap.org/appid. Add a .env file with:

APPID = YOUR_APP_ID

License

Licensed under the MIT license.