Function open

  • Pre-fetches databases from the mirror.

    Type Parameters

    • DbReaderInstance extends {}

      The type of a database reader instance. You can either supply it manually or let Typescript infer it from the readerInitializer param.

    Parameters

    • dbName: GeoIpDbName

      The database to open. You can find available databases in the GeoIpDbName enum or use string names directly in JS. Will be downloaded if it hasn't already been fetched (see downloadDbs to pre-fetch at an earlier time).

    • readerInitializer: ((path: string) => DbReaderInstance | Promise<DbReaderInstance>)

      A function that takes the absolute path to the downloaded .mmmdb database and returns a new DbReaderInstance. You need to supply it to this library so we can re-initialize your reader when the databases are auto-updated.

    • OptionaldownloadDirPath: string

      The path to the directory where the database should be stored. Defaults to ./node_modules/node-geolite2-redist/dbs. See downloadDbs for more information.

    Returns Promise<WrappedReader<DbReaderInstance>>

    A Promise that resolves with your reader instance when the databases have been successfully downloaded and your reader initialized. Calling .close() on the reader will gracefully stop the background databases auto-updater, and run the reader's actual close() method if there is one, supporting arguments passthrough.