Getting started with Turf.js

There are a few different ways to get started using Turf, the documentation below will provide a couple of the common scenarios.

Using in Node or with a build tool

If you're working in Node or with build tool (such as webpack, browserify or rollup) you can include individual turf modules in your project.

// Import your module of interest
var collect = require('@turf/collect');
// or in ES6
import collect from '@turf/collect';
// And then use it
collect(points, polys, 'population', 'populationValues');
// Alternatively you can import the whole lot using
import * as turf from '@turf/turf'

Using directly in the browser

Load the minified file via a script tag, this will expose a global variable named turf.

<script src=''></script>
    var bbox = turf.bbox(features);

Note: The full build of Turf weighs around 500kb which is a fair bit of javascript to load so you probably only want to pull in the bits you need, see the instructions below on how to create a custom build.

Creating custom builds for use in the browser

Step 1 Create a folder and install whatever modules you are interested in via npm

$ npm install @turf/collect @turf/buffer

Step 2 Create a file called main.js in the root directory, in this include your required modules within a modules.exports statement

module.exports = {
    collect: require('@turf/collect'),
    buffer: require('@turf/buffer')

Step 3 Run the following browserify command

$ browserify main.js -s turf > outTurf.js 

Done You can now use your outTurf.js file where you want just like you would normally use Turf, eg load it via a script tag and call turf using the turf global variable.


Below are some helpful resources for getting started with Turf.

Code Repositories

Turf & Node.js for geoprocessing tasks


Intro To Turf

Analysis with Turf.js