Lightweight module that lets you easily fetch google's autocomplete suggestions for a given seed term.
Install the package:
npm install google-autocomplete
And do this:
auto = require('google-autocomplete');
auto.getQuerySuggestions('house', function(err, suggestions) {
console.log(suggestions);
})
To get this:
[
{ suggestion: 'house of cards', relevance: 750, type: 'QUERY' },
{ suggestion: 'house of prime rib', relevance: 600, type: 'QUERY' },
{ suggestion: 'house of cards season 3', relevance: 566, type: 'QUERY' },
{ suggestion: 'house of cards season 2', relevance: 565, type: 'QUERY' }
]
-
autocomplete.getQuerySuggestions(query, callback)
fetches allQUERY
type
results (other types of results includeNAVIGATION
,IMAGE
, and more). Expects a standard callback function to provide (err, result) arguments to. -
autocomplete.getAllSuggestions(query, callback)
fetches all types of suggestion types (result set will include things like places and images, see above). Expects a standard callback function to provide (err, result) arguments to.
Both methods return an array of objects which include a relevance
score based on Google Search's judgment. See the above sample for example.