Skip to main content

Examples

Leaflet

Mapbox

D3.js

Quick Reference Examples

Getting all counties

census({
  vintage: "2017",
  geoHierarchy: {
    county: "*"
  },
  sourcePath: ["acs", "acs5"],
  values: ["B19083_001E"], // GINI index
  statsKey: "<your key here>",
  geoResolution: "500k"
});

Saving the file locally in Node.js using fs

var fs = require("fs");

census(
  {
    vintage: 2017,
    geoHierarchy: {
      "metropolitan statistical area/micropolitan statistical area": "*"
    },
    geoResolution: "500k" // required
  },
  (err, res) => {
    fs.writeFile("./directory/filename.json", JSON.stringify(res), () =>
      console.log("done")
    );
  }
);

This would convert the returned geojson to a string, which allows it to be saved via Node.js’ fileSystem API.