Since you are a beginner at Node, I'll try to give you a step by step answer
Firstly you need to install Node on your system. The exact steps will depend on your Operating system, and version, but it's a good bet that you will find the installer at https://nodejs.org/download/
You should also note that if you have an updated installer, then NPM or the Node Package Manager will also be installed for you.
Now you need to install turf on your system. The Node way of doing this, is to create a folder, and then install the library inside that folder, so that you can work inside that folder.
Open the Node.js command prompt (if you are on windows), and go to your working directory. Then type npm install turf
. This command will download the required files (turf as well as dependencies) from the internet, and install it your working directory.
Now that you have installed the library, you will want to use it. Generally speaking, Node modules & libraries do not have any UI of their own. You call them in your own Nodejs scripts.
You want to buffer and get the buffered output as GeoJSON. Here is an example script that buffers a polygon, and writes the output as a GeoJSON file
//Import the required modules
var turf = require( "turf" );
var fs = require('fs');
//input GeoJSON Feature
var mumbai={"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[72.7752778054935,19.2690995044639],[72.7817405956684,19.1238719055124],[72.8102749851638,19.1265959946878],[72.8247751057141,19.0910359643985],[72.8153720376396,19.0437583107182],[72.8209940779221,19.0352490234709],[72.8329105061117,19.0434886443927],[72.8359963318184,19.0373312064806],[72.8231900924928,19.0205055493087],[72.8125475128558,19.029908429424],[72.8080633067106,18.9898352623244],[72.7870845004595,18.947660113865],[72.7942309393155,18.937263881405],[72.809080960536,18.9503035811928],[72.8217391510222,18.9394947874404],[72.799135569344,18.9068306279723],[72.8113769649099,18.8893472433276],[72.8218126386322,18.8951870964281],[72.8474780411575,18.9235963464463],[72.8675088075429,19.0019646776918],[72.8819781251631,19.0064190047499],[72.8877097499884,18.9888559741936],[72.9236539940438,18.9983155390154],[72.9660988576404,19.0502455556637],[72.9836291475658,19.1747956918978],[72.9248922078066,19.2203564322991],[72.8998650805814,19.2558042171924],[72.8514714066599,19.2738226789422],[72.8514714066599,19.2738226789422],[72.8514714066599,19.2738226789422],[72.7752778054935,19.2690995044639]]]},"properties":{}};
//Buffer it by 500 meters
var buffered = turf.buffer(mumbai, 500, 'meters');
//try writing to a file
fs.writeFile("D:/buffered.geojson", JSON.stringify(buffered), function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
//also display on Console
console.log("The Output Generated was: ");
console.log(buffered);
Best Answer
Got it, create a JS object and load it with features from the GeoJSON file. Next loop through the object passing it through the turf function inside.