var request = require("request");

function getNDB(currentSearch, callback) {
	request('http://api.nal.usda.gov/ndb/search/?format=json&q=' + currentSearch +  '&sort=n&max=25&offset=0&api_key=UqyGauU4aSQSifon8gyVK5riyMn5ubZinIHBOk5B', function (error, response, body) {
	  if (!error && response.statusCode == 200) {
	  	data = JSON.parse(body).list.item;
	  	niceData = []; 	
	    for ( i=0; i<data.length; i++ ) {
	    	niceData.push([data[i].group, data[i].name, data[i].ndbno]);
	    }
	    callback(JSON.stringify(niceData));
	  }
	});
}



getNDB("cheese", function(data){console.log(data)});
@@ -27,16 +27,17 @@
 uest%22);%0A
+ 
 %0Afunctio
@@ -72,17 +72,24 @@
 back) %7B%0A
-%09
+        
 request(
@@ -271,17 +271,24 @@
 body) %7B%0A
-%09
+        
   if (!e
@@ -325,20 +325,36 @@
  200) %7B%0A
-%09  %09
+                var 
 data = J
@@ -384,12 +384,28 @@
 em;%0A
-%09  %09
+                var 
 nice
@@ -419,11 +419,22 @@
 %5B%5D; 
-%09%0A%09
+     %0A        
     
@@ -471,14 +471,24 @@
 ) %7B%0A
-%09    %09
+                
 nice
@@ -548,16 +548,30 @@
 %5D);%0A
-%09    %7D%0A%09
+            %7D%0A        
     
@@ -610,37 +610,1670 @@
 ));%0A
-%09  %7D%0A%09%7D);%0A%7D%0A%0A%0A%0AgetNDB(%22cheese
+          %7D%0A        %7D);%0A%7D%0A %0Afunction getCalorie(ndb, callback) %7B%0A        request('http://api.nal.usda.gov/ndb/reports/?ndbno=' + ndb + '&type=f&format=json&api_key=UqyGauU4aSQSifon8gyVK5riyMn5ubZinIHBOk5B', function (error, response, body) %7B%0A                var data = JSON.parse(body).report.food.nutrients;%0A                var energy = %5B%5D;%0A                var parsedEnergy = %5B%5D;%0A                for ( i=0; i%3Cdata.length; i++ ) %7B%0A                        if ( data%5Bi%5D.name == %22Energy%22) %7B%0A                                if ( data%5Bi%5D.unit == %22kcal%22) %7B%0A                                        energy = data%5Bi%5D;%0A                                %7D%0A                        %7D%0A                %7D%0A                parsedEnergy%5B'calories'%5D = %5B%5D;%0A                parsedEnergy%5B'calories'%5D%5B'value'%5D =  energy.value;%0A                parsedEnergy%5B'calories'%5D%5B'measure'%5D = %22100%22;%0A                callback(parsedEnergy);%0A        %7D);%0A%7D%0A %0Afunction energyBurnt(age, weight, exercise, time, gender, callback) %7B%0A        var heartrate = 0;%0A        if ( exercise == %22walking%22 ) %7B%0A                heartrate = 130;%0A        %7D else if ( exercise == %22running%22) %7B%0A                heartrate = 170;%0A        %7D%0A        if ( gender == %22man%22 ) %7B%0A                var CaloriesBurnt = (age * 0.2017 - weight * 0.09036 + heartrate * 0.6309 - 55.0969) * (time / 4.184);%0A        %7D else %7B%0A                var CaloriesBurnt = (age * 0.074 - weight * 0.05741 + heartrate * 0.4472 - 20.4022) * (time / 4.184);%0A        %7D%0A        callback(CaloriesBurnt);%0A%7D%0A %0A//getNDB(%22cheese%22, function(data)%7Bconsole.log(data)%7D);%0A//getCalorie(%2243449%22, function(data)%7Bconsole.log(data)%7D);%0AenergyBurnt(49, 155, %22walking%22, 60, %22man
 %22, f

Include changes from @popey456963