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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@geoapify/un-locode

v1.0.3

Published

A Node.js library for querying United Nations Location Code (UN/LOCODE) data

Readme

@geoapify/un-locode

A lightweight Node.js helper for querying United Nations Location Code (UN/LOCODE) data locally. Look up a single location by country and place code and get back normalized metadata, functional designations, and coordinates (when available).

Installation

npm install @geoapify/un-locode

Usage

query is synchronous and returns either a UnlocodeItem object or null. Country and location codes must be uppercase ISO 3166-1 alpha-2 and UN/LOCODE values respectively.

CommonJS:

const { query } = require('@geoapify/un-locode');

const aberdeen = query('US', 'APG');
console.log(aberdeen?.locationName); // "Aberdeen"

ESM / TypeScript:

import { query } from '@geoapify/un-locode';
import type { UnlocodeItem } from '@geoapify/un-locode';

const aberdeen: UnlocodeItem | null = query('US', 'APG');

Parameters

  • countryCode (string): ISO 3166-1 alpha-2 code (US, DE, SG, ...).
  • locationCode (string): Three-character UN/LOCODE location code (APG, HAM, ...).

Response

Example return value:

{
  "country": "US",
  "location": "APG",
  "locationName": "Aberdeen",
  "subdivision": "MD",
  "status": "AI",
  "functionCodes": ["3", "4"],
  "coordinates": {
    "lat": 39.5120347,
    "lon": -76.1643289
  }
}
  • country: ISO country code.
  • location: UN/LOCODE location code.
  • locationName: Name without diacritics.
  • subdivision: Optional state/province value.
  • status: Two-letter UN/LOCODE status code.
  • functionCodes: Array of functional designations (see below).
  • coordinates: Optional WGS84 latitude/longitude pair.

Note: Some rows in the original UN/LOCODE dump lack coordinates. We enrich those rows with the Geoapify Geocoding API when generating the bundled dataset.

Function Codes

  • 1 = Port (any waterborne transport)
  • 2 = Rail terminal
  • 3 = Road terminal
  • 4 = Airport
  • 5 = Postal exchange office
  • 6 = Inland Clearance Depot (ICD) / dry port
  • 7 = Fixed transport functions (pipelines, power lines, ropeways, etc.)
  • B = Border crossing
  • 0 = Function unknown / not specified

Status Codes

  • AA: Approved by a competent national government agency
  • AC: Approved by Customs Authority
  • AF: Approved by a national facilitation body
  • AI: Adopted by an international organization (e.g., IATA or ECLAC)
  • AM: Approved by the UN/LOCODE Maintenance Agency
  • AQ: Entry approved, functions not verified
  • AS: Approved by a national standardization body
  • RL: Recognized location confirmed by a gazetteer or other reference
  • RN: Request from credible national sources for locations within their country
  • RQ: Request under consideration
  • UR: Entry included on user’s request; not officially approved
  • RR: Request rejected
  • QQ: Original entry not verified since the indicated date
  • XX: Entry to be removed in the next issue of UN/LOCODE

Caching Behavior

The library lazily loads CSV files per-country and keeps them in memory for 24 hours. Long-running processes benefit from repeated queries, while the cache automatically purges stale entries. If you need tighter control (for instance, to release memory after batch processing), restart the process or load only the countries you require.

Data Source & Updates

  • The repository currently ships with the UNECE 2024-2 UN/LOCODE release (published January 2025) found in data-source/2024-2 UNLOCODE CodeList.csv.
  • Geoapify’s Geocoding API is used to supplement coordinates for rows that lack latitude/longitude in the official dump.
  • To regenerate the JSON/CSV assets for a newer dataset:
    1. Place the new CSV/XLS file inside data-source/.
    2. Add your API_KEY to src/utility/utility.ts (used during geocoding).
    3. Run npm run generate-files (see BUILD.md for details).

Requirements

  • Node.js 18.0.0 or newer (the generator scripts rely on modern ECMAScript features).
  • npm (comes with Node) for running the provided scripts.

Install dependencies once via npm install, then use the commands below as needed.

Development Workflow

Running tests

npm test

Building the library

npm run build-all

This compiles the TypeScript sources and bundles the packaged JSON assets.

Regenerating JSON data

  1. Drop the latest CSV/XLS export into the root data-source/ folder.

  2. Add your Geoapify API key to src/utility/utility.ts.

  3. Run:

    npm run generate-files

Running the demo

  1. Build the project (npm run build-all).

  2. Start the demo app:

    npm run start:demo

Error Handling

query returns null when the provided country/location combination does not exist. Make sure to guard for this in your application.

Contributing

Contributions are welcome! Please fork the repository, make your changes, and submit a pull request. See BUILD.md for full data-generation instructions.