Vietnam Administrative Address Database
This package provides a raw JSON database of Vietnamese administrative addresses, meticulously structured according to Resolution 202/2025/QH15 and NQ-UBTVQH15, with applicability from July 1, 2025, and January 1, 2025, respectively. As of version 1.0.0, it includes data for 34 provinces/cities, 3,321 wards/communes, and 10,977 ward mapping rules. It is explicitly designed as a dependency for other JavaScript/TypeScript libraries, offering unopinionated access to the latest administrative boundary data. The package ships with comprehensive TypeScript type definitions, enabling robust static type checking for consumers. Its core differentiator is providing a directly consumable, machine-readable dataset reflecting future administrative changes.
Common errors
-
TypeError: addressData.find is not a function
cause The default export `addressData` is an array of `DatabaseItem`s (header, database info, tables), not a direct array of provinces or wards. You cannot directly call `.find()` on `addressData` to locate a province.fixFirst, iterate through `addressData` to extract the specific 'table' you need (e.g., `provinces`), then apply array methods like `.find()` to the extracted table: `const provinces = addressData.find(item => item.name === 'provinces')?.data as Province[]; provinces.find(...)` -
Error: Cannot find module 'vietnam-address-database'
cause The package was not correctly installed or there's a typo in the import path.fixEnsure the package is installed: `npm install vietnam-address-database`. Double-check the import statement for typos: `import addressData from 'vietnam-address-database';` or `const addressData = require('vietnam-address-database');`
Warnings
- gotcha The administrative data provided in this package is based on future resolutions (202/2025/QH15 and NQ-UBTVQH15) which apply from July 1, 2025, and January 1, 2025, respectively. This means the data may not reflect the *current* administrative boundaries prior to these dates.
- gotcha This package exports raw JSON data in a structured array. It does not provide utility functions for querying, indexing, or managing the data. Consumers must implement their own logic to parse the array and extract the desired tables (provinces, wards, ward_mappings).
- gotcha As a new package (v1.0.0), while the data structure is clearly defined, future major versions might introduce schema changes to the raw JSON output to accommodate new government resolutions or improved data representation. Always consult release notes for breaking changes.
Install
-
npm install vietnam-address-database -
yarn add vietnam-address-database -
pnpm add vietnam-address-database
Imports
- addressData
const addressData = require('vietnam-address-database');import addressData from 'vietnam-address-database';
- Province
import type { Province } from 'vietnam-address-database'; - Ward
import type { Ward } from 'vietnam-address-database'; - WardMapping
import type { WardMapping } from 'vietnam-address-database'; - DatabaseItem
import type { DatabaseItem } from 'vietnam-address-database';
Quickstart
import addressData, { Province, Ward, WardMapping, DatabaseItem } from 'vietnam-address-database';
// The exported data is an array of DatabaseItem, which includes header, database info, and tables.
const allData: DatabaseItem[] = addressData;
// Extract specific tables for easier access and type safety
let provinces: Province[] = [];
let wards: Ward[] = [];
let wardMappings: WardMapping[] = [];
allData.forEach(item => {
if (item.type === 'table') {
if (item.name === 'provinces') {
provinces = item.data as Province[];
} else if (item.name === 'wards') {
wards = item.data as Ward[];
} else if (item.name === 'ward_mappings') {
wardMappings = item.data as WardMapping[];
}
}
});
// Example functions to work with the extracted data
function getProvinces(): Province[] {
console.log(`Found ${provinces.length} provinces.`);
return provinces;
}
function getProvinceByCode(code: string): Province | undefined {
const province = provinces.find(p => p.province_code === code);
console.log(`Province for code '${code}': ${province?.name || 'Not found'}`);
return province;
}
// Usage examples:
const haNoi = getProvinceByCode('01'); // Example: Hà Nội
const firstWard = wards[0];
if (firstWard) {
console.log(`First ward: ${firstWard.name}, code: ${firstWard.ward_code}`);
}
const firstMapping = wardMappings[0];
if (firstMapping) {
console.log(`First ward mapping: Old: ${firstMapping.old_ward_name} (${firstMapping.old_ward_code}), New: ${firstMapping.new_ward_name} (${firstMapping.new_ward_code})`);
}