Guide · Open source
How to use Turf: install @turf/turf and run spatial analysis in JavaScript
Updated · written with AI from the project's own documentation and checked against our catalogue data
Turf is an open-source JavaScript and TypeScript library for spatial analysis. It provides common spatial operations, helpers for creating GeoJSON data, and tools for data classification and statistics. This guide shows you how to install it, where it runs, and what it is and is not suited for, so you can start adding map-related calculations to a web app or Node.js project.
Quick start
- 1Check Node.js. Install an Active or Maintenance LTS release of Node.js, which the README recommends.
- 2Install Turf. Run npm install @turf/turf in your project folder to add the full Turf package.
- 3Confirm your data is GeoJSON. Turf works with GeoJSON data, so make sure your geographic input is in that format.
- 4Read the getting started guide. Open turfjs.org/docs/getting-started to learn the basic workflow and function names.
- 5Call Turf functions in your code. Import the functions you need and run spatial operations or helpers on your GeoJSON.
- 6Bundle for the browser if needed. If you run in a web page, use your build setup to transpile and polyfill Turf for your target browsers.
What Turf is and what it is not
Turf is a code library, not a finished map application. You call its functions from your own JavaScript or TypeScript, and it returns results you can use in your project.
It is built to work with GeoJSON data. If your project already uses GeoJSON, Turf fits naturally. It is released under the MIT licence.
- Good fit: developers adding map calculations to a website or web app
- Good fit: Node.js developers processing GeoJSON on a server
- Good fit: teams that want to import only the modules they need
- Not a fit: people who want a map app with no coding
- Not a fit: full GIS desktop work, such as with QGIS
Install Turf with npm
Turf is installed with a package manager. The README gives this command to install the full Turf package.
Node.js is the prerequisite for the server side. The README recommends an Active or Maintenance LTS release of Node.js.
npm install @turf/turfChoose where Turf runs: browser or Node.js
Turf can be added to a website as a client-side module. It can also run on a server with Node.js. The README says it is published to work with any reasonably modern JavaScript runtime, but Node.js is the first-class option.
Deno and Bun are not officially supported according to the README. The project says it would be interested to hear about experiences using them.
If you bundle Turf for the browser, make sure your build setup transpiles and polyfills Turf and all its transitive dependencies to match your target browsers. The @turf/turf package includes a browser bundle that combines all Turf modules into a single minified JavaScript file.
Read the getting started guide and API docs
The official getting started guide at turfjs.org/docs/getting-started walks you through working with Turf. The API and examples are also on turfjs.org.
Start with the docs rather than guessing function names, since the library is organised as many modules.
Common problems to check first
If Turf fails to run, first confirm you are on a Node.js release the README recommends, and that you are not relying on Deno or Bun, which are not officially supported.
If a browser build fails on older targets, check your bundler's transpile and polyfill settings for Turf and its dependencies, as the README advises.
- Confirm your Node.js version is an Active or Maintenance LTS release
- Confirm your runtime is Node.js or a browser
- Check transpile and polyfill settings in your bundler
What people use it for
- Calculating spatial relationships between points and areas inside a web app
- Processing GeoJSON data on a Node.js server
- Creating GeoJSON features with Turf helper functions
- Classifying data and computing statistics on geographic datasets
- Importing only specific Turf modules to keep a bundle smaller
Frequently asked questions
Is Turf free to use?
Yes. Turf is released under the MIT licence, as stated in the project's listing. Check the licence file in the repository for the full terms.
What do I need to install Turf?
You need Node.js, and the README recommends an Active or Maintenance LTS release. You then install the package with npm install @turf/turf.
Can I use Turf in the browser?
Yes. Turf can be added to a website as a client-side module, and @turf/turf includes a browser bundle in a single JavaScript file. Your build setup should transpile and polyfill Turf for your target browsers.
Does Turf work with Deno or Bun?
Not officially. The README says Deno and Bun are not officially supported, though the maintainers would like to hear about experiences using them.
Is Turf a replacement for QGIS?
No. Turf is a JavaScript library for spatial analysis in code, not a full GIS desktop tool such as QGIS.
What are alternatives to Turf?
Comparable projects listed for this item include JSTS, Proj4js, Mapshaper and d3-geo. Each covers different parts of geospatial work, so pick based on what your project needs.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Turf suits developers who write JavaScript or TypeScript and work with GeoJSON in browsers or on Node.js, especially when they want to import only the modules they need. If you want a finished map application with no coding, or you need a desktop GIS tool or a runtime other than Node.js or browsers, pick a different tool.
Install options & downloads