Simple Instagram metadata scraping library for Node.js, written in TypeScript.
π Full Documentation
β Buy Me a Coffee
npm install insta-fetcherInstagram requires a valid session cookie for most requests. Get yours with getCookie:
import { igApi, getCookie } from 'insta-fetcher';
// Get session cookie (only need to do this once)
const cookie = await getCookie('your_username', 'your_password');
console.log(cookie);
// Initialize with cookie
const ig = new igApi(cookie);Note: Save your cookie somewhere (e.g.
.env) so you don't need to login every time.
const ig = new igApi(cookie, {
proxy: {
host: 'proxy-url',
port: 'proxy-port',
auth: {
username: 'proxy-user',
password: 'proxy-password'
}
}
});const post = await ig.fetchPost('https://www.instagram.com/p/xxxxx/');
console.log(post);
/*
{
username: 'fiiyya21',
name: 'Fiya',
postType: 'image',
media_id: '2841182589568357263_3026954032',
shortcode: 'Cdt6IP7Pd2D',
taken_at_timestamp: 1652915380,
likes: 3,
caption: 'some caption here',
media_count: 2,
comment_count: 15,
video_duration: null,
music: null,
links: [
{
id: '...',
url: 'https://...',
type: 'image',
dimensions: { height: 720, width: 720 }
}
]
}
*/// Simple user info
const user = await ig.fetchUserV2('username');
console.log(user);
// Detailed user info (includes email, phone if public)
const userDetail = await ig.fetchUser('username');
console.log(userDetail);
// Get user ID from username
const userId = await ig.getIdByUsername('username');
console.log(userId);const stories = await ig.fetchStories('username');
console.log(stories);
/*
{
username: 'username',
stories_count: 3,
stories: [
{
type: 'image' | 'video',
url: 'https://...',
taken_at: 1652915380,
expiring_at: 1652915380,
...
}
]
}
*/const highlights = await ig.fetchHighlights('username');
console.log(highlights);
/*
{
username: 'username',
highlights_count: 5,
data: [
{
title: 'Highlight Title',
cover: 'https://...',
media_count: 10,
highlights_id: '...',
highlights: [ ... ]
}
]
}
*/// First page
const posts = await ig.fetchUserPostsV2('username');
// Next page using next_max_id
const nextPosts = await ig.fetchUserPostsV2('username', 'next_max_id');const reels = await ig.fetchUserReel('username');
// With pagination
const nextReels = await ig.fetchUserReel('username', 'end_cursor');// Fetches your own account info based on cookie
const account = await ig.accountInfo();
console.log(account);const userId = await ig.getIdByUsername('username');
const followers = await ig.searchFollower(userId, 'search_term');
const following = await ig.searchFollowing(userId, 'search_term');// Post to feed
await ig.addPost('./photo.jpg', 'feed', {
caption: 'Hello from insta-fetcher!'
});
// Post to story
await ig.addPost('./photo.jpg', 'story', {});await ig.changeProfilePicture('./new_photo.jpg');All contributions are welcome β code, bug reports, documentation, or new features.
- Fork this repo
- Create your branch:
git checkout -b feat/your-feature - Commit your changes:
git commit -m 'feat: add some feature' - Push to the branch:
git push origin feat/your-feature - Open a Pull Request
- nganu β WhatsApp Bot using this library