@dukebot/instagram-collector
v1.0.3
Published
Instagram collector module with Mongoose models and services built on top of @dukebot/instagram-scraper-api.
Maintainers
Readme
@dukebot/instagram-collector
Instagram collector module for Node.js using ES Modules, Mongoose, and @dukebot/instagram-scraper-api.
This package adds a persistence layer on top of the scraper so Instagram accounts and posts can be stored in MongoDB and processed later from your own backend jobs.
Features
- Track Instagram accounts in MongoDB
- Enable or disable tracked accounts
- Store collected Instagram posts in MongoDB
- Run a simple sequential extraction process
- No build step, plain modern JavaScript
Installation
npm install @dukebot/instagram-collectorExports
InstagramAccountInstagramPostInstagramAccountServiceInstagramPostServiceInstagramExtractionServiceutils
Basic Usage
import mongoose from 'mongoose';
import { InstagramScraperAPI } from '@dukebot/instagram-scraper-api';
import {
InstagramAccountService,
InstagramExtractionService,
} from '@dukebot/instagram-collector';
await mongoose.connect(process.env.MONGODB_URI);
const scraper = new InstagramScraperAPI({
apiHost: process.env.INSTAGRAM_SCRAPER_API_HOST,
apiKey: process.env.INSTAGRAM_SCRAPER_API_KEY,
});
const instagramAccountService = new InstagramAccountService({ scraper });
await instagramAccountService.put('instagram');
const instagramExtractionService = new InstagramExtractionService({ scraper });
const summary = await instagramExtractionService.run();
console.log(summary);Account Service
const service = new InstagramAccountService({ scraper });
await service.put('nasa');
await service.get();
await service.get({ isActive: true });
await service.getOne({ username: 'nasa' });
await service.getOne({ id: '123456' });
await service.setIsActive({ username: 'nasa', isActive: false });Post Service
import { InstagramPostService } from '@dukebot/instagram-collector';
const service = new InstagramPostService();
await service.get();
await service.get({ username: 'nasa' });
await service.getOne({ code: 'ABC123' });Extraction Service
The extraction service:
- Loads all active accounts
- Fetches posts for each account sequentially
- Creates or updates posts in MongoDB
- Returns a simple summary object
Example result:
{
processedAccounts: 2,
failedAccounts: 0,
processedPosts: 24,
createdPosts: 10,
updatedPosts: 14,
errors: []
}Notes
- The module is intentionally simple and does not include scheduling logic.
- Run your daily sync from cron, PM2, GitHub Actions, or your backend worker.
- The extraction process is sequential by design.
License
MIT
