Login

Factual Blog /

Factual Node.js Driver

We’re pleased to announce the release of the officially supported Node.js driver for Factual.

Get going!

You can get the driver using npm…

$ npm install factual-api

…and then install it in your project and connect:

var Factual = require('factual-api');
var factual = new Factual('YOUR_KEY', 'YOUR_SECRET');

(If you don’t have an API key, sign up to get one. It’s free and easy.)

Basic Query Example

Do a full-text search of the restaurant database for rows that match the terms “Coffee, Los Angeles”

factual.get('/t/restaurants-us',{q:"Coffiee, Los Angeles"}, function (error, res) {
  console.log("show "+ res.included_rows +"/"+ res.total_row_count +" rows:", res.data);
});

You can find out more about basic query capabilities in the docs for our Core API docs.

Geo Filter Example

The driver supports all of Factual’s Geo Filtering. Here’s an example of finding Starbucks locations near a latitude, longitude:

factual.get('/t/places', {q:"starbucks",
                          geo:{"$circle":{"$center":[34.041195,-118.331518],"$meters":1000}}},
                          function (error, res) {
  console.log(res.data);
});

Crosswalk Example

Factual’s Crosswalk service lets you map third-party (Yelp, Foursquare, etc.) identifiers for businesses or points of interest to each other where each ID represents the same place.

Here’s an example using the Node.js driver to query with a factual id, getting entites from Yelp and Foursquare:

factual.get('/places/crosswalk', {"factual_id":"57ddbca5-a669-4fcf-968f-a1c8210a479a",
                                   only:"yelp,foursquare"},
                                   function (error, res) {
  console.log(res.data);
});

Resolve

Use Factual’s Resolve to enrich your data and match it against Factual’s:

//
// Resolve an entity, starting with the business name and location:
//
factual.get('/places/resolve', {values:{"name":"huckleberry",
                                        "latitude":34.023827,
                                        "longitude":-118.49251}},
                                function (error, res) {
  console.log(res.data);
});

We’ve put great effort into making our public API fast. We know you expect your Node projects to be fast too. Use this driver to access Factual’s data platform, be fast, and go do great work!

Sincerely,
Aaron
Software Engineer