npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2025 – Pkg Stats / Ryan Hefner

irctc-connect

v2.1.3

Published

πŸš‚ Complete Node.js SDK for Indian Railways IRCTC - Check PNR status, train schedules, live running status, seat availability & station info. Promise-based API with TypeScript support.

Readme

IRCTC Connect

npm version Downloads License

A comprehensive Node.js package for Indian Railways services. Get real-time PNR status, detailed train information, live train tracking, station updates, search trains between stations, and check seat availability with fare information.

✨ Features

  • 🎫 PNR Status Checking - Real-time PNR status with passenger details
  • πŸš‚ Train Information - Complete train details with route information
  • πŸ“ Live Train Tracking - Real-time train status and location tracking
  • πŸš‰ Live Station Updates - Current trains at any station
  • πŸ” Train Search - Find trains between any two stations
  • πŸ’Ί Seat Availability - Check availability with fare breakdown for multiple dates
  • πŸ—ΊοΈ Route Details - Station-wise route with timings and coordinates
  • ⚑ Fast & Reliable - Built-in timeout handling and validation

πŸ“¦ Installation

npm install irctc-connect

πŸš€ Quick Start

import { 
    checkPNRStatus, 
    getTrainInfo, 
    trackTrain, 
    liveAtStation, 
    searchTrainBetweenStations,
    getAvailability
} from 'irctc-connect';

// Check PNR status
const pnrResult = await checkPNRStatus('1234567890');

// Get train information
const trainResult = await getTrainInfo('12345');

// Track live train status
const trackResult = await trackTrain('12345', '03-12-2025');

// Get live trains at station
const stationResult = await liveAtStation('NDLS');

// Search trains between stations
const searchResult = await searchTrainBetweenStations('NDLS', 'BCT');

// Get seat availability with fare
const availabilityResult = await getAvailability('12496', 'ASN', 'DDU', '27-12-2025', '2A', 'GN');

πŸ“– API Reference

1. checkPNRStatus(pnr)

Get comprehensive PNR status with passenger details and journey information.

Parameters:

  • pnr (string): 10-digit PNR number

Example:

const result = await checkPNRStatus('1234567890');

if (result.success) {
    console.log('PNR:', result.data.pnr);
    console.log('Status:', result.data.status);
    console.log('Train:', result.data.train.name);
    console.log('Journey:', `${result.data.journey.from.name} β†’ ${result.data.journey.to.name}`);
    
    // Show all passengers
    result.data.passengers.forEach(passenger => {
        console.log(`${passenger.name}: ${passenger.status} - ${passenger.seat}`);
    });
}

2. getTrainInfo(trainNumber)

Get detailed train information including complete route with station coordinates.

Parameters:

  • trainNumber (string): 5-digit train number

Example:

const result = await getTrainInfo('12345');

if (result.success) {
    const { trainInfo, route } = result.data;
    
    console.log(`πŸš‚ ${trainInfo.train_name} (${trainInfo.train_no})`);
    console.log(`πŸ“ ${trainInfo.from_stn_name} β†’ ${trainInfo.to_stn_name}`);
    console.log(`⏱️ ${trainInfo.from_time} - ${trainInfo.to_time} (${trainInfo.travel_time})`);
    console.log(`πŸ“… Running Days: ${trainInfo.running_days}`);
    
    // Show route (first 5 stations)
    console.log('\nπŸ›€οΈ Route:');
    route.slice(0, 5).forEach(station => {
        console.log(`  ${station.stnName} (${station.stnCode}) - ${station.departure}`);
    });
}

3. trackTrain(trainNumber, date)

Get real-time train status and tracking for a specific date with detailed station-wise information including delays and coach positions.

Parameters:

  • trainNumber (string): 5-digit train number
  • date (string): Date in dd-mm-yyyy format

Example:

const result = await trackTrain('12342', '03-12-2025');

if (result.success) {
    const { trainNo, trainName, date, statusNote, lastUpdate, totalStations, stations } = result.data;
    
    console.log(`πŸš‚ ${trainName} (${trainNo})`);
    console.log(`πŸ“… Date: ${date}`);
    console.log(`πŸ“ Status: ${statusNote}`);
    console.log(`πŸ• Last Update: ${lastUpdate}`);
    console.log(`πŸ›€οΈ Total Stations: ${totalStations}`);
    
    // Show station details with delays
    console.log('\nπŸ“‹ Station Details:');
    stations.forEach(station => {
        console.log(`\n  πŸš‰ ${station.stationName} (${station.stationCode})`);
        console.log(`     Platform: ${station.platform} | Distance: ${station.distanceKm} km`);
        console.log(`     Arrival: ${station.arrival.scheduled} β†’ ${station.arrival.actual}`);
        if (station.arrival.delay) {
            console.log(`     ⚠️ Arrival Delay: ${station.arrival.delay}`);
        }
        console.log(`     Departure: ${station.departure.scheduled} β†’ ${station.departure.actual}`);
        if (station.departure.delay) {
            console.log(`     ⚠️ Departure Delay: ${station.departure.delay}`);
        }
        
        // Show coach composition
        if (station.coachPosition && station.coachPosition.length > 0) {
            const coaches = station.coachPosition.map(c => c.type).join(' - ');
            console.log(`     πŸšƒ Coaches: ${coaches}`);
        }
    });
}

Response Structure:

{
    success: true,
    data: {
        trainNo: "12342",
        trainName: "AGNIVEENA EXP",
        date: "03-Dec-2025",
        statusNote: "Arrived at HOWRAH JN(HWH) at 09:06 03-Dec (Delay: 00:06)",
        lastUpdate: "03-Dec-2025 09:11",
        totalStations: 8,
        stations: [
            {
                stationCode: "ASN",
                stationName: "ASANSOL JN.",
                platform: "5",
                distanceKm: "",
                arrival: {
                    scheduled: "SRC",
                    actual: "SRC",
                    delay: ""
                },
                departure: {
                    scheduled: "05:30 03-Dec",
                    actual: "05:30 03-Dec",
                    delay: "On Time"
                },
                coachPosition: [
                    { type: "ENG", number: "ENG", position: "0" },
                    { type: "LPR", number: "LPR", position: "1" },
                    { type: "GEN", number: "GEN", position: "2" },
                    { type: "2S", number: "D5", position: "4" },
                    { type: "CC", number: "C2", position: "9" }
                    // ... more coaches
                ]
            },
            {
                stationCode: "RNG",
                stationName: "RANIGANJ",
                platform: "4",
                distanceKm: "18",
                arrival: {
                    scheduled: "05:41 03-Dec",
                    actual: "05:50 03-Dec",
                    delay: "9 Min"
                },
                departure: {
                    scheduled: "05:43 03-Dec",
                    actual: "05:52 03-Dec",
                    delay: "9 Min"
                },
                coachPosition: [
                    // ... coach details
                ]
            }
            // ... more stations
        ]
    }
}

4. liveAtStation(stationCode) πŸ†•

Get list of upcoming trains at any station with real-time information.

Parameters:

  • stationCode (string): Station code (e.g., 'NDLS', 'BCT', 'HWH')

Example:

const result = await liveAtStation('NDLS');

if (result.success) {
    console.log(`πŸš‰ Live trains at ${result.data.stationName}:`);
    
    result.data.trains.forEach(train => {
        console.log(`πŸš‚ ${train.trainName} (${train.trainNumber})`);
        console.log(`   πŸ“ ${train.source} β†’ ${train.destination}`);
        console.log(`   ⏰ Expected: ${train.expectedTime}`);
        console.log(`   πŸ“Š Status: ${train.status}`);
        if (train.delay) {
            console.log(`   ⚠️ Delay: ${train.delay}`);
        }
        console.log('   ---');
    });
}

Response Structure:

{
    success: true,
    data: {
        stationName: "New Delhi",
        stationCode: "NDLS",
        lastUpdated: "2025-06-28 14:30:00",
        trains: [
            {
                trainNumber: "12345",
                trainName: "Rajdhani Express",
                source: "New Delhi",
                destination: "Mumbai Central",
                expectedTime: "20:05",
                actualTime: "20:10",
                status: "On Time",
                delay: "5 min",
                platform: "16"
            }
            // ... more trains
        ]
    }
}

5. searchTrainBetweenStations(fromStationCode, toStationCode) πŸ†•

Find all trains running between two stations with timing and availability.

Parameters:

  • fromStationCode (string): Origin station code
  • toStationCode (string): Destination station code

Example:

const result = await searchTrainBetweenStations('NDLS', 'BCT');

if (result.success) {
    console.log(`πŸ” Trains from ${result.data.from} to ${result.data.to}:`);
    console.log(`πŸ“Š Found ${result.data.trains.length} trains\n`);
    
    result.data.trains.forEach(train => {
        console.log(`πŸš‚ ${train.trainName} (${train.trainNumber})`);
        console.log(`   ⏰ Departure: ${train.departure} | Arrival: ${train.arrival}`);
        console.log(`   ⏱️ Duration: ${train.duration}`);
        console.log(`   πŸ“… Days: ${train.runningDays}`);
        console.log(`   πŸ’Ί Classes: ${train.availableClasses.join(', ')}`);
        console.log('   ---');
    });
}

Response Structure:

{
    success: true,
    data: {
        from: "New Delhi (NDLS)",
        to: "Mumbai Central (BCT)", 
        totalTrains: 15,
        trains: [
            {
                trainNumber: "12345",
                trainName: "Rajdhani Express",
                departure: "20:05",
                arrival: "08:35",
                duration: "12h 30m",
                runningDays: "Daily",
                availableClasses: ["1A", "2A", "3A"],
                trainType: "Superfast"
            }
            // ... more trains
        ]
    }
}

6. getAvailability(trainNo, fromStnCode, toStnCode, date, coach, quota) πŸ†•

Get seat availability with fare information for a train journey. Returns availability status for multiple dates along with detailed fare breakdown.

Parameters:

  • trainNo (string): 5-digit train number
  • fromStnCode (string): Origin station code (e.g., 'ASN', 'NDLS')
  • toStnCode (string): Destination station code (e.g., 'DDU', 'BCT')
  • date (string): Date in DD-MM-YYYY format (e.g., "27-12-2025")
  • coach (string): Travel class - one of: "2S", "SL", "3A", "3E", "2A", "1A", "CC", "EC"
  • quota (string): Booking quota - one of: "GN" (General), "LD" (Ladies), "SS" (Senior Citizen), "TQ" (Tatkal)

Example:

const result = await getAvailability('12496', 'ASN', 'DDU', '27-12-2025', '2A', 'GN');

if (result.success) {
    const { train, fare, availability } = result.data;
    
    console.log(`πŸš‚ ${train.trainName} (${train.trainNo})`);
    console.log(`πŸ“ ${train.fromStationName} (${train.from}) β†’ ${train.toStationName} (${train.to})`);
    console.log(`πŸ“ Distance: ${train.distance} km`);
    console.log(`πŸ’Ί Class: ${train.travelClass} | Quota: ${train.quota}`);
    
    // Fare breakdown
    console.log('\nπŸ’° Fare Breakdown:');
    console.log(`   Base Fare: β‚Ή${fare.baseFare}`);
    console.log(`   Reservation Charge: β‚Ή${fare.reservationCharge}`);
    console.log(`   Superfast Charge: β‚Ή${fare.superfastCharge}`);
    console.log(`   Service Tax: β‚Ή${fare.serviceTax}`);
    console.log(`   Total Fare: β‚Ή${fare.totalFare}`);
    
    // Availability for multiple dates
    console.log('\nπŸ“… Availability:');
    availability.forEach(avail => {
        console.log(`\n   πŸ“† ${avail.date}`);
        console.log(`      Status: ${avail.status}`);
        console.log(`      Availability: ${avail.availabilityText}`);
        console.log(`      Prediction: ${avail.prediction} (${avail.predictionPercentage}%)`);
        console.log(`      Can Book: ${avail.canBook ? 'βœ… Yes' : '❌ No'}`);
    });
}

Response Structure:

{
    success: true,
    data: {
        train: {
            trainNo: "12496",
            trainName: "PRATAP EXPRESS",
            from: "ASN",
            to: "DDU",
            fromStationName: "Asansol Junction",
            toStationName: "Pt. Deen Dayal Upadhyaya Junction",
            distance: 461,
            travelClass: "2A",
            quota: "GN"
        },
        fare: {
            baseFare: 981,
            reservationCharge: 50,
            superfastCharge: 45,
            serviceTax: 54,
            totalFare: 1130
        },
        availability: [
            {
                date: "27-12-2025",
                status: "WAITLIST",
                availabilityText: "Regret",
                rawStatus: "REGRET",
                prediction: "No More Booking",
                predictionPercentage: 0,
                canBook: false
            },
            {
                date: "17-1-2026",
                status: "WAITLIST",
                availabilityText: "WL 2",
                rawStatus: "PQWL9/WL2",
                prediction: "90% Chance",
                predictionPercentage: 90,
                canBook: true
            }
            // ... more dates
        ]
    }
}

Coach Types:

  • 2S - Second Seating
  • SL - Sleeper Class
  • 3A - Third AC
  • 3E - Third AC Economy
  • 2A - Second AC
  • 1A - First AC
  • CC - Chair Car
  • EC - Executive Chair Car

Quota Types:

  • GN - General Quota
  • LD - Ladies Quota
  • SS - Senior Citizen Quota
  • TQ - Tatkal Quota

πŸ›‘οΈ Input Validation

PNR Number

  • βœ… Must be exactly 10 digits
  • βœ… Automatically removes non-numeric characters
  • βœ… Validates format before API call

Train Number

  • βœ… Must be exactly 5 characters
  • βœ… Should be valid train number string

Date Format

  • βœ… Must be dd-mm-yyyy format (e.g., "28-06-2025")
  • βœ… Validates actual date values
  • βœ… No invalid dates like 32-01-2025

Station Codes

  • βœ… Must be valid station code strings
  • βœ… Common codes: NDLS, BCT, HWH, CSTM, SBC, etc.

πŸ“Š Common Status Codes

| PNR Status | Description | |------------|-------------| | CNF | Confirmed - Seat confirmed | | WL | Waiting List - Not confirmed yet | | RAC | Reservation Against Cancellation | | CAN | Cancelled | | PQWL | Pooled Quota Waiting List | | TQWL | Tatkal Quota Waiting List |

| Train Status | Description | |-------------|-------------| | On Time | Running as scheduled | | Delayed | Running behind schedule | | Cancelled | Train service cancelled | | Diverted | Route changed |

⚠️ Error Handling

All functions return consistent response structure:

// βœ… Success
{
    success: true,
    data: { /* response data */ }
}

// ❌ Error  
{
    success: false,
    error: "Description of what went wrong"
}

Always check the success field before accessing data!

πŸ”§ Requirements

  • Node.js 14+ (for native fetch support)
  • Internet connection for API calls
  • Valid inputs (PNR numbers, train numbers, station codes)

πŸ“± Platform Support

  • βœ… Node.js applications
  • βœ… Express.js servers
  • βœ… Next.js applications
  • βœ… React Native (with polyfills)
  • βœ… Electron apps

🀝 Contributing

We welcome contributions! Here's how you can help:

  1. 🍴 Fork the repository
  2. 🌟 Create a feature branch
  3. πŸ’» Make your changes
  4. βœ… Add tests if applicable
  5. πŸ“ Update documentation
  6. πŸš€ Submit a pull request

πŸ“„ License

MIT License - feel free to use in your projects!

πŸ™‹β€β™‚οΈ Support

🌟 Star History

If this package helped you, please give it a ⭐ on GitHub!


Built with ❀️ for Indian Railways enthusiasts

Happy Journey! πŸš‚