A library to test if a url/request is crawled, usually used in a web crawler. Compatible with request and node-crawler. The 1.x or newer version has quite different APIs and is not compatible with 0.x versions. Please read the upgrade guide document.
$ npm install seenreq --save
constseenreq=require('seenreq'),seen=newseenreq();//url to be normalizedleturl="http://www.GOOGLE.com";console.log(seen.normalize(url));//{ sign: "GET http://www.google.com/\r\n", options: {}}//request options to be normalizedletoption={uri: 'http://www.GOOGLE.com',rupdate: false};console.log(seen.normalize(option));//{sign: "GET http://www.google.com/\r\n", options:{rupdate: false}}seen.initialize().then(()=>{returnseen.exists(url);}).then((rst)=>{console.log(rst[0]);//false if ask for a `request` never seereturnseen.exists(opt);}).then((rst)=>{console.log(rst[0]);//true if got same `request`}).catch(e){console.error(e);};When you call exists, the module will do normalization itself first and then check if exists.
seenreq stores keys in memory by default, memory usage will soar as number of keys increases. Redis will solve this problem. Because seenreq uses ioredis as redis client, all ioredis' options are recived and supported. You should first install:
npminstallseenreq-repo-redis--saveand then set repo to redis:
constseenreq=require('seenreq')letseen=newseenreq({repo:'redis',// use redis instead of memoryhost:'127.0.0.1',port:6379,clearOnQuit:false// clear redis cache or don't when calling dispose(), default true.});seen.initialize().then(()=>{//do stuff...}).catch(e){console.error(e);}It is similar with redis above:
npminstallseenreq-repo-mongo--saveconstseenreq=require('seenreq')letseen=newseenreq({repo:'mongo',url:'mongodb://xxx/seenreq',collection: 'foor'});Instance of seenreq
Initialize the repo, returns a promise.
uriString,optionis Option of request or node-crawler- options
Returns normalized Object: {sign,options}.
- uri|option
- options
Returns a promise with an Boolean array, e.g. [true, false, true, false, false].
Dispose resources of repo. If you are using repo other than memory, like Redis you should call dispose to release connection. Returns a promise.
- removeKeys: Array, Ignore specified keys when doing normalization. For instance, there is a
tsproperty in the url likehttp://www.xxx.com/index?ts=1442382602504which is timestamp and it should be same whenever you visit. - stripFragment: Boolean, Remove the fragment at the end of the URL (Default true).
- rupdate: Boolean, it is short for
repo update. Store in repo so thatseenreqcan hit the samereqnext time (Default true).
- add
mysqlrepo to persist keys to disk. - add keys life time management.

