data collection | https://www.amazon.com/gp/yourstore/iyr/ref=pd_ys_iyr_nextie=UTF8&collection=watched&iyrGroup=&maxItem=616&minItem=600 | schedule search all | Search

The searchAll function is a main exported function that retrieves search results from multiple search engines in parallel using the multiCrawl function, and saves the results to a JSON file in the user's Collections/searches directory. The function takes an optional query parameter and returns a promise that resolves to an object containing search results, with the file name constructed from the query string and the current date.

Run example

npm run import -- "meta search all"

meta search all

var fs = require('fs');
var path = require('path');
var importer = require('../Core');
var multiCrawl = importer.import("multi crawl");

// http://www.exploratorium.edu/files/ronh/research/index.html
/*

 Exploratorium	
 Search
 Google	
 Search
 alltheweb	
 Search
 Teoma	
 Search
 AltaVista	
 Search
 Wisenut	
 Search
 HotBot	
 Search
 lii.org	
 Search
 Northern Light	
 Search
 Lycos	
 Search
 Scirus	
 
 Meta:
 Ask Jeeves	
 Search
 MetaCrawler	
 Search
 Dogpile	
 Search
 SavvySearch	
 
 
 */
var PROFILE_PATH = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE || '';
var project = path.join(PROFILE_PATH, 'Collections/searches');

function searchAll(query = 'search engine') {
    var engines = [
        'https://www.google.com/search?q=' + query,
        'https://www.bing.com/search?q=' + query,
        'https://search.yahoo.com/search?p=' + query,
        'https://www.ask.com/web?q=' + query,
        'https://search.aol.com/aol/search?q=' + query,
        'http://www.baidu.com/s?wd=' + query,
        'https://www.wolframalpha.com/input/?i=' + query,
        'https://duckduckgo.com/?q=' + query,
        'https://www.yandex.com/search/?text=' + query,
        'https://archive.org/search.php?query=' + query,
    ];
    
    // TODO: save results
    return multiCrawl(engines, 'search results json')
        .then(r => {
            const time = new Date();
            fs.writeFileSync(path.join(project, query.replace(/[^a-z0-9]/ig, '_')
                                       + '-' + time.getFullYear()
                                       + '-' + (time.getMonth() + 1)
                                       + '-' + time.getDate()
                                       + '.json'), JSON.stringify(r, null, 4));
            return r;
        })
}
module.exports = searchAll;

if(typeof $ !== 'undefined') {
    $.async();
    searchAll()
        .then(r => $.sendResult(r))
        .catch(e => $.sendError(e))
}

What the code could have been:

const fs = require('fs').promises;
const path = require('path');
const multiCrawl = require('../Core').import('multi crawl');

const PROFILE_PATH = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE || '';
const PROJECT_PATH = path.join(PROFILE_PATH, 'Collections','searches');

async function searchAll(query ='search engine') {
    try {
        const engines = [
            'https://www.google.com/search?q=' + encodeURIComponent(query),
            'https://www.bing.com/search?q=' + encodeURIComponent(query),
            'https://search.yahoo.com/search?p=' + encodeURIComponent(query),
            'https://www.ask.com/web?q=' + encodeURIComponent(query),
            'https://search.aol.com/aol/search?q=' + encodeURIComponent(query),
            'http://www.baidu.com/s?wd=' + encodeURIComponent(query),
            'https://www.wolframalpha.com/input/?i=' + encodeURIComponent(query),
            'https://duckduckgo.com/?q=' + encodeURIComponent(query),
            'https://www.yandex.com/search/?text=' + encodeURIComponent(query),
            'https://archive.org/search.php?query=' + encodeURIComponent(query),
        ];

        const results = await multiCrawl(engines,'search results json');
        const timestamp = new Date().toISOString().replace(/:/g, '-').replace('.', '-');
        const filename = query.replace(/[^a-z0-9]/ig, '_') + '-' + timestamp + '.json';
        const filePath = path.join(PROJECT_PATH, filename);

        await fs.writeFile(filePath, JSON.stringify(results, null, 4));
        return results;
    } catch (error) {
        throw error;
    }
}

module.exports = searchAll;

if (typeof $!== 'undefined') {
    $.async();
    searchAll()
       .then((results) => $.sendResult(results))
       .catch((error) => $.sendError(error));
}

Code Breakdown

Dependencies and Imports

Variables and Constants

searchAll Function

File Saving

Export and Usage