a simple way to get image results from a google custom search engine using node
- Google Custom Search Engine - Create a Google CSE
- Google API Key for the CSE
This module uses the dotenv package to manage environment variables In your main app you will also need to use dotenv Create two new Keys in your .env file and set the values to your CSE ID and your Google CSE API Keys
- CSE_ID=
- CSE_API_KEY=
In your app require the module Within your code call the module with the following parameters
- Search Term
- Callback function (will be called once results are ready)
- ID number of result you want to offset from
- Number of results you want (between 1-10 inclusive)
index.js of main app
var imageSearch = require('node-google-image-search');
var results = imageSearch('<search-term>', callback, 0, 5);
function callback(results) {
_do something with results_;
}
Maximum number of results from Google CSE is 100, this app will return up to 10 at a time. So, if offset + number of results wanted > 100 then nothing will be returned