turf
A modular geospatial engine written in JavaScript and TypeScript
A modular JavaScript library that brings GIS mapping analysis, distance, area, intersection, clustering, directly into browser or Node.js apps using standard GeoJSON data.
Turf is a JavaScript library for working with geographic data. It provides functions for spatial analysis: things like calculating the distance between two locations, finding whether a point falls inside a polygon, measuring areas, combining shapes, and running statistical calculations on geographic datasets. These are the kinds of operations you normally associate with dedicated mapping software or GIS (Geographic Information System) tools, but Turf makes them available directly in JavaScript code.
The library works with a data format called GeoJSON, which is a standard way of representing geographic features (points, lines, polygons, collections of these) as JSON text. Most web mapping tools already speak GeoJSON, so Turf slots naturally into projects that use libraries like Leaflet or Mapbox to display maps.
Turf can run in two places. In a browser, you include it as a JavaScript module on the page. On a server, you install it through npm (the Node.js package manager) and run it as part of a backend application. The library is modular, meaning you can install just the specific functions you need rather than pulling in the entire package, which keeps your project's file size down.
The project is open source, funded through Open Collective where individuals and companies can become backers or sponsors. It is actively maintained and accepts contributions through GitHub. Official documentation and interactive examples are available at turfjs.org. Browser support targets any reasonably modern browser, and Node.js is treated as a first-class runtime environment.
Where it fits
- Check whether a delivery address falls inside a specific service area polygon on a map.
- Calculate the distance between two user-placed map markers and display it in kilometers.
- Measure the area of user-drawn regions on an interactive Leaflet or Mapbox map.
- Cluster geographic data points server-side in a Node.js backend before sending them to a map.