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 🙏

© 2026 – Pkg Stats / Ryan Hefner

states-cities-db

v1.4.1

Published

States & cities library

Readme

State Cities


Get a list of countries, or give it a country & get a list of states, or give it a state, and it will give you an array of all the city names in that state

Install it

NPM

$ npm install state-cities-db --save

Yarn

$ yarn add state-cities-db

Add it

var sc = require('state-cities-db');

Usage

Get countries

// Get all countries
var countries = sc.getCountries();

//Sample response
console.log(countries);

[ { name: 'Afghanistan',
    slug: 'afghanistan',
    iso: 'AFG',
    prefix: '+93',
    currency: 'AFN',
    region: 'Asia',
    subregion: 'Southern Asia',
    latlng: [ 33, 65 ] },
  { name: 'Albania',
    slug: 'albania',
    iso: 'ALB',
    prefix: '+355',
    currency: 'ALL',
    region: 'Europe',
    subregion: 'Southern Europe',
    latlng: [ 41, 20 ] }]

Get states

// Get all states
var states = sc.getStates(); 

// OR
// Get all states by passing the country slug.
var states = sc.getStates('nigeria'); 

//Sample response
console.log(states);

[ { name: 'Abia',
    slug: 'nigeria_abia',
    stateSlug: 'abia',
    country: 'nigeria' },
  { name: 'Adamawa',
    slug: 'nigeria_adamawa',
    stateSlug: 'adamawa',
    country: 'nigeria' },
  { name: 'Akwa Ibom',
    slug: 'nigeria_akwa-ibom',
    stateSlug: 'akwa-ibom',
    country: 'nigeria' },
  { name: 'Anambra',
    slug: 'nigeria_anambra',
    stateSlug: 'anambra',
    country: 'nigeria' } ]

// Filter States
// Get all states in nigeria that contain the string 'ab'.
var filteredStates = sc.getStates('nigeria', 'ab');

//Sample response
console.log(filteredStates);

[ { name: 'Abia',
    slug: 'nigeria_abia',
    stateSlug: 'abia',
    country: 'nigeria' },
  { name: 'Taraba',
    slug: 'nigeria_taraba',
    stateSlug: 'taraba',
    country: 'nigeria' } ]

Note: You can get the country slug from the getCountries() method.

Get cities

// Get all cities
var cities = sc.getCities(); 

// OR
// Get all cities by passing the state slug.
var cities = sc.getCities('nigeria_lagos'); 

//Sample response
console.log(cities);

[ { name: 'Agege',
    slug: 'nigeria_lagos_agege',
    citySlug: 'agege',
    state: 'nigeria_lagos',
    country: 'nigeria' },
  { name: 'Ajeromi Ifelodun',
    slug: 'nigeria_lagos_ajeromi-ifelodun',
    citySlug: 'ajeromi-ifelodun',
    state: 'nigeria_lagos',
    country: 'nigeria' },
  { name: 'Alimosho',
    slug: 'nigeria_lagos_alimosho',
    citySlug: 'alimosho',
    state: 'nigeria_lagos',
    country: 'nigeria' } ]

// Filter cities
// Get all cities in lagos, nigeria that contain the string 'ike'.
var filteredCities = sc.getCities('nigeria_lagos', 'ike'); 

//Sample response
console.log(filteredCities);

[ { name: 'Ikeja',
    slug: 'nigeria_lagos_ikeja',
    citySlug: 'ikeja',
    state: 'nigeria_lagos',} ]

Note: You can get the state slug from the getStates() method.

Get item by slug

// Get by slug
var country = sc.getBySlug('country', 'nigeria');
var state = sc.getBySlug('state', 'nigeria_lagos');
var city = sc.getBySlug('city', 'nigeria_lagos_apapa');

//Sample responses
console.log(country);

{ name: 'Nigeria',
  slug: 'nigeria',
  iso: 'NGA',
  prefix: '+234',
  currency: 'NGN',
  region: 'Africa',
  subregion: 'Western Africa',
  latlng: [ 10, 8 ] }

console.log(state);

{ name: 'Lagos',
  slug: 'nigeria_lagos',
  stateSlug: 'lagos',
  country: 'nigeria' }

console.log(city);

{ name: 'Apapa',
  slug: 'nigeria_lagos_apapa',
  citySlug: 'apapa',
  state: 'nigeria_lagos',
  country: 'nigeria' }

TODO

  • Add cities for other countries (Currently only Nigerian cities pupolated)

PRs are welcome :)