psgc-areas
Version:
Provides the full Philippine Standard Geographic Code (PSGC) dataset in JSON with multiple formats (hierarchy, flat list of all areas, regions, provinces, cities, municipalities, municipal districts, and barangays).
17 lines (14 loc) • 520 B
JavaScript
import fs from "node:fs/promises";
import path from "node:path";
import url from "node:url";
export function resolvePath(aPath) {
const __filename = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
return path.resolve(__dirname, aPath);
}
export async function readJSON(aBasename) {
const filename = aBasename + ".json";
const filepath = resolvePath(path.join("./data", filename));
const data = await fs.readFile(filepath, "utf8");
return JSON.parse(data);
}