Skip to content

Instantly share code, notes, and snippets.

@AndrewSepic
Created August 26, 2025 20:09
Show Gist options
  • Save AndrewSepic/4e99a658f22b34423829e4b7f6246ecc to your computer and use it in GitHub Desktop.
Save AndrewSepic/4e99a658f22b34423829e4b7f6246ecc to your computer and use it in GitHub Desktop.
Parse & read GeoJSON features with fs
import fs from 'fs';
const filePath = './public-schools.geojson';
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
if (data.type === 'FeatureCollection' && Array.isArray(data.features)) {
console.log(`Found ${data.features.length} features`);
data.features.forEach((feature, index) => {
const { properties, geometry } = feature;
// Example: Print NAME and coordinates
console.log(`${index + 1}: ${properties.NAME} -> ${geometry.coordinates}`);
});
} else {
console.log('File is not a featureCollection with features');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment