Use the Index class to scan a directory, compare it against a local SQLite database, and cache metadata for fast retrieval. You can trigger an update by calling .update(path, options). This method returns an emitter that provides lifecycle events for stats, progress, individual files, and completion.
const Index = require('./index/index')
// Initialize with a database file name
const index = new Index('thumbsup.db')
// Start indexing a folder
const emitter = index.update('/Volumes/photos', {
concurrency: 2,
includePhotos: true,
includeVideos: true,
includeRawPhotos: false,
})
// Listen for lifecycle events
emitter.on('stats', stats => {
// stats contains: total, unchanged, added, modified, deleted
})
emitter.on('progress', progress => {
// progress contains: path, completed, total
})
emitter.on('file', file => {
// file contains: path, timestamp, metadata
})
emitter.on('done', () => {
console.log('Finished indexing')
})