Socket
Book a DemoInstallSign in
Socket

nodejs-insta-private-api

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodejs-insta-private-api

A pure JavaScript Instagram Private API client inspired by instagram-private-api

Source
npmnpm
Version
4.8.4
Version published
Weekly downloads
691
25.87%
Maintainers
1
Weekly downloads
 
Created
Source

nodejs-insta-private-api

VERSION 3.3.1 Update library for latest Instagram Version
A pure JavaScript Instagram Private API client written in CommonJS without TypeScript.

npm version License: MIT

Repository: Kunboruto20/nodejs-insta-private-api

Features

  • 🔐 Authentication - Username, email and password login with session management
  • 💬 Direct Messages - Send text, images, and videos to users and groups
  • 📱 Stories - React to stories, upload content, and view story feeds
  • 📤 Feed Operations - Upload photos/videos, like, comment, and browse timeline
  • 🍪 Session Management - Save and restore login sessions
  • 🔄 Auto-retry - Built-in retry logic for failed requests
  • 📋 Comprehensive API - 50+ methods covering most Instagram features
  • 🚀 High Performance - Optimized for speed and reliability
  • 📡 Realtime MQTT - Real-time events via MQTT using edge-mqtt.facebook.com (GraphQL, Pub/Sub, Message Sync, Iris)

📡 Realtime MQTT Features

The realtime service provides comprehensive Instagram real-time messaging:

  • Correct Endpoint - Uses edge-mqtt.facebook.com (Instagram's official MQTT broker)
  • All Topics Supported - GraphQL, Pub/Sub, Message Sync, Iris, Region Hints
  • Automatic Reconnection - Robust error handling with exponential backoff
  • Message Parsing - Dedicated parsers for each message type
  • Event System - Comprehensive event handling for all realtime activities

Installation

npm install nodejs-insta-private-api

Quick Start

Basic Usage

const { IgApiClient } = require('nodejs-insta-private-api');

async function main() {
  const ig = new IgApiClient();
  
  try {
    await ig.login({ 
      username: 'your_username', 
      password: 'your_password',
      email: 'your_email@example.com' 
    });
    
    console.log('✅ Logged in successfully!');
    
    await ig.dm.send({ 
      to: 'friend_username', 
      message: 'Hello from the API!' 
    });
    
    console.log('✅ Message sent!');
    
  } catch (error) {
    console.error('❌ Error:', error.message);
  }
}

main();

Realtime Usage

const { IgApiClient } = require('nodejs-insta-private-api');

async function main() {
  const ig = new IgApiClient();
  
  try {
    await ig.login({ 
      username: 'your_username', 
      password: 'your_password',
      email: 'your_email@example.com' 
    });
    
    await ig.connectRealtime();
    
    ig.realtime.on('messageSync', (data) => {
      console.log('💬 Message sync:', data);
    });
    
    ig.realtime.on('graphqlMessage', (data) => {
      console.log('🔍 GraphQL message:', data);
    });
    
    ig.realtime.on('pubsubMessage', (data) => {
      console.log('📢 Pub/Sub message:', data);
    });
    
    console.log('✅ Connected to realtime!');
    
  } catch (error) {
    console.error('❌ Error:', error.message);
  }
}

main();

🔌 Extending with instagram_mqttt

This library can be extended with instagram_mqttt to add Realtime and FBNS (Push Notifications) support.

Installation

npm install instagram_mqttt

Extend the IgApiClient

import { IgApiClient } from 'nodejs-insta-private-api';
import { withFbnsAndRealtime, withFbns, withRealtime } from 'instagram_mqttt';

// Wrap the client
const ig = withFbnsAndRealtime(new IgApiClient());

// OR if you only want fbns/realtime
const igFbns = withFbns(new IgApiClient());
const igRealtime = withRealtime(new IgApiClient());

// login as usual, then use ig.realtime and ig.fbns

RealtimeClient Features

  • Typing Events
  • Presence Events
  • Direct Messaging
  • Live Comments
  • Live Events

FbnsClient Usage

FBNS is for notifications (readonly). You can subscribe to any notification:

ig.fbns.on('push', (data) => {
  console.log('Push notification:', data);
});

Or subscribe to a specific event:

ig.fbns.on('collapseKey', (data) => {
  console.log('Specific notification:', data);
});

Authentication

(… keep all authentication examples …)

Direct Messages

(… keep DM examples …)

Stories

(… keep story examples …)

Feed Operations

(… keep feed examples …)

User Operations

(… keep user examples …)

Media Operations

(… keep media examples …)

Realtime MQTT Events

(… keep realtime events section …)

Error Handling

(… keep error handling examples …)

Advanced Usage

(… keep advanced usage examples …)

API Reference

(… keep API reference section …)

Requirements

  • Node.js >= 14.0.0
  • Valid Instagram account

Dependencies

  • axios
  • tough-cookie
  • form-data
  • chance
  • lodash

Contributing

Repository: Kunboruto20/nodejs-insta-private-api

  • Fork the repository
  • Create your feature branch (git checkout -b feature/amazing-feature)
  • Commit your changes (git commit -m 'Add some amazing feature')
  • Push to the branch (git push origin feature/amazing-feature)
  • Open a Pull Request

License

MIT License - see LICENSE

Disclaimer

This library is for educational purposes only. Use at your own risk and in compliance with Instagram's Terms of Service.

Support

  • ⭐ Star the repo
  • 🐛 Report bugs
  • 💡 Suggest features
  • 📖 Improve docs

Changelog

v4.7.0

  • 🚀 New realtime system using edge-mqtt.facebook.com
  • 📡 Support for all Instagram realtime topics
  • 🔧 Dedicated parsers
  • 🔄 Automatic reconnection
  • 📊 Comprehensive event system
  • 🛡️ Fixed previous realtime issues
  • 📚 Updated docs

v1.0.0

  • Initial release
  • Full Instagram Private API implementation
  • 50+ methods
  • Error handling
  • Session management
  • Pure JavaScript

Keywords

instagram

FAQs

Package last updated on 09 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts