railway-api-wrapper-v2

This is a module contains promise based wrappers that are created around the Indian Railway API - https://railwayapi.com


Keywords
Indian, Railway, Railways, API, Node, Express, Node.js, Indian Railways, IRCTC, PNR, Status, Train, Async, Await, Async/Await, Promise
License
MIT
Install
npm install railway-api-wrapper-v2@1.0.0

Documentation

Railway API Wrapper v2

This module contains promise based wrappers that are created around the Indian Railway API.

Note:- This wrapper uses the v2 of Indian Railway API (This is the latest version as of March'19).

Installation

npm install --save railway-api-wrapper-v2

Get The API Key

Click on the link to get the unique developer's API key. You can get a free API key for development purpose.

Usage Example

  • Resolving promises using Async/Await

    const railway = require("railway-api-wrapper-v2");
    
    // Set the API key that you will get from Indian Railways API website
    railway.setApiKey("<API key>");
    
    // Self calling function (because await keyword can only be used inside an async function)
    (async () => {
      try {
        let res = await railway.nameOrNumber("Mahalaxmi");
        console.log(res);
      } catch (err) {
        /*
          Handling Error
          console.log('Error Object:', err)
          console.log('Error Message:', err.message)
    
          if(err.error_code){
            console.log('Error Code:', err.error_code)
          }
        */
      }
    })();
  • Resolving promises using then((data)=>{}) & catch((err)=>{})

    const railway = require("railway-api-wrapper-v2");
    
    // Set the API key that you will get from Indian Railways API website
    railway.setApiKey("<API key>");
    
    railway
      .nameOrNumber("Mahalaxmi")
      .then(res => {
        console.log(res);
      })
      .catch(err => {
        console.log(err);
        /*
          Handling Error
          console.log('Error Object:', err)
          console.log('Error Message:', err.message)
    
          if(err.error_code){
            console.log('Error Code:', err.error_code)
          }
        */
      });

Docs

List of all the functions can be found in the Documentation

FAQ

  • Found Bugs? Want To Give Feedback?

    Check if there is any existing issue which matches your query, if not create one and ask your query or raise a Bug! Pull Requests are welcomed.

  • Is there a callback based wrapper around Indian Railway API?

    Check out this Github Repository - Railway API Wrapper

Support

If you like the package you can show your support by starring this Github Project! Thanks a lot! :)