npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-bom

v0.2.4

Published

NodeJS/Typescript library to access Australian Bureau of Meteorology data.

Downloads

22

Readme

node-bom

NodeJS/Typescript library to access Australian Bureau of Meteorology weather data.

npm version

Examples

Importing

import { Bom } from 'node-bom'

const bom = new Bom({
  /// options
})

Getting BOM's parsed state weather data:

bom.getParsedStateData('VIC', {
  bypassCache: false // default: false to use cache
})
  .then((stateData) => {
    console.log(stateData)
    /*
      {
        forecast: {}, // forecast data
        observations: {} // current station's observations data
      }
    */
  })

Get current weather data. There are 3 methods to query current data and forecast data:

  • Using a longitude latitude (slowest, as it needs to find the nearest station)
  • Using an Australian postcode (e.g. 3141, 2000)
  • Using a station ID (e.g. '250042' - use stateFilter param to speed up)

Current data (or Station's observation)

bom.getNearestStation(-33.833, 150.52808) //Sydney
  .then((nearestStation) => {
    console.log(nearestStation) // nearest station data
  })

bom.getNearestStationByPostcode(3000) // Melbourne
  .then((nearestStation) => {
    console.log(nearestStation) // nearest station data
  })

bom.getStationByBomId('250042', 'NSW')
  /* **Note**: the second parameter is optional, however due to the way
  BOM structures their dataset, the station data is tied to a state.
  Without specifying a state, the library will attempt to download all state data
  and this might cause excessive long time. Therefore it's recommended to use this
  api with the state filter param */
  .then((station) => {
    console.log(station)
  })

Get weather forecast data

// Getting forecast data based on latitude / longitude
bom.getForecastData(-33.833, 150.52808) // Sydney
  .then((data) => {
    console.log(data)
  })

// Getting forecast data based on postcode
bom.getForecastDataByPostcode(3141) // South Yarra, VIC
  .then((data) => {
    console.log(data)
  })

// Getting forecast data based on postcode
bom.getForecastDataByStationId('NSW_PW006', 'NSW')
  /* **Note**: the second parameter is optional, however due to the way
  BOM structures their dataset, the station data is tied to a state.
  Without specifying a state, the library will attempt to download all state data
  and this might cause excessive long time. Therefore it's recommended to use this
  api with the state filter param */
  .then((data) => {
    console.log(data)
  })

Using an external package to resolve geoip such as geoip-lite, you can resolve the geolocation then utilise it to find weather data

import * as geoip from 'geoip-lite'
// Getting forecast data based on IP address
// this depends on an external package: `geoip-lite`

const ipData = geoip.lookup('134.178.253.144') // BOM IP Address
bom.getForecastData(ipData.ll[0], ipData.ll[1])
  .then((data) => {
    console.log(data)
  })

bom.getForecastDataByIpAddress('134.178.253.144') // BOM IP Address
  .then((data) => {
    console.log(data)
  })

Caching

This library utilises caching heavily. The library uses memory caching by default using node cache-manager.

It's recommended that you change to a custom cache backend:

File cache:

import { Bom } from 'node-bom'
import * as fsStore from 'cache-manager-fs-hash'

const bom = new Bom({
  cacheStore: fsStore,
  cacheOptions: {
    // additional cache options go here, this will be passed to cache-manager
    options: {
      path: './tmp'
    }
  }
})

Redis cache:

import { Bom } from 'node-bom'
import * as redisStore from 'cache-manager-ioredis'

const bom = new Bom({
  cacheStore: redisStore,
  cacheOptions: {
    host: 'localhost',
    port: 6379,
    db: 0,
    ttl: 600
  }
})

Building the library

  1. Clone the repo
  2. Install node_modules
npm install
  1. Update the au_postcodes.js file (it automatically detects the latest nearest station list and cache the station's ID onto the file)
npm run update-nearest-station
  1. Test / Package up
npm run test
npm run dist

MIT Licensed

Weather data © Copyright Commonwealth of Australia 2018, Bureau of Meteorology http://www.bom.gov.au