Introducing DigiPIN.js: India's Coordinate-to-Postal Code Converter for Developers

Rajat GuptaRajat Gupta
4 min read

Why India Needs a Better Location System

As developers, we often deal with messy, inconsistent address data - especially in India. Think of long, ambiguous addresses, missing landmarks, and PIN codes that don’t tell us exactly where someone is.

But what if we had a compact, precise, and standardized way to represent any location in India?

Meet DIGIPIN:

DIGIPIN (Digital Postal Index Number) is a government-backed system that converts GPS coordinates into short, human-readable codes - like:

28.6139°N, 77.2090°E → 39J-438-TJC7

It was developed by:

  • Department of Posts, Govt of India

  • Indian Institute of Technology, Hyderabad

  • National Remote Sensing Centre, ISRO

📦 Introducing digipinjs

To help developers integrate DIGIPIN into real-world apps, I built digipinjs - a full-featured, TypeScript-first library for working with DIGIPIN codes.

🔧 What It Does

  • 🔁 Convert coordinates ↔ DIGIPIN

  • ⚡ Batch encode/decode

  • 🧠 LRU caching for fast repeat lookups

  • 🧪 Fully typed, clean API

  • 🧵 Built-in CLI tool

  • 🌐 Express middleware support

  • 🗺️ Grid generation + reverse geocoding

🚀 Quick Start

📥 Installation

npm install digipinjs
# or yarn add digipinjs

🧪 Usage Examples

1. Use from the CLI

npx digipin-cli encode --lat 28.6139 --lng 77.2090
# Output: 39J-438-TJC7

npx digipin-cli decode --pin 39J-438-TJC7
# Output: Latitude: 28.613901, Longitude: 77.208998

You can even use DMS format or verbose output:

npx digipin-cli encode --lat 28.6139 --lng 77.2090 --verbose --format dms

2. Programmatic Use

import { getDigiPin, getLatLngFromDigiPin } from 'digipinjs';

const pin = getDigiPin(28.6139, 77.2090);
console.log(pin); // "39J-438-TJC7"

const coords = getLatLngFromDigiPin(pin);
console.log(coords); // { latitude: 28.6139, longitude: 77.2090 }

3. Batch Processing

const pins = batchEncode([
  { lat: 28.6139, lng: 77.2090 },  // Delhi
  { lat: 19.0760, lng: 72.8777 },  // Mumbai
  { lat: 12.9716, lng: 77.5946 }   // Bangalore
]);

console.log(pins);
// ["39J-438-TJC7", "4FK-595-8823", "2L7-3K9-8P2F"]

4. Express Middleware Integration

import express from 'express';
import { digiPinMiddleware } from 'digipinjs';

const app = express();
app.use(digiPinMiddleware()); // adds `X-DIGIPIN` header based on coordinates

🧠 How the DIGIPIN Format Works

DIGIPIN uses a 10-character format split with hyphens:

XXX-XXX-XXXX

It’s generated using a 16-character alphabet optimized for postal use:

Characters: F, C, 9, 8, J, 3, 2, 7, K, 4, 5, 6, L, M, P, T

This encoding ensures:

  • ✨ Compactness

  • 🧍‍♂️ Human readability

  • 📍 Location accuracy

  • 🧭 Uniform coverage of the entire Indian subcontinent


⚠️ Error Handling

try {
  getDigiPin(100, 200); // Out of bounds
} catch (error) {
  console.error(error.message); // "Latitude out of range"
}

Invalid codes are handled cleanly too:

getLatLngFromDigiPin("INVALID");
// throws: "Invalid DIGIPIN"

🛠️ Dev Tools Included

  • npm run build – compile TypeScript

  • npm run lint – run ESLint

  • npm test – full test suite

  • node examples/full-usage-npm.js – example script


📈 Performance

OperationSpeed
Encode~10,000 ops/sec
Decode~15,000 ops/sec
Cache Hit Rate95%+
Memory FootprintSmall (up to 10,000 entries in LRU)

👥 Who Should Use This?

  • E-commerce devs standardizing delivery coordinates

  • Real estate platforms geotagging properties

  • GIS/mapping developers

  • Emergency response tools

  • Indian civic-tech & govtech hackers

  • React Native apps with location services


🤝 Contribute/Collaborate

This project is open source under a dual license:

  • Wrapper (digipinjs) - MIT

  • Original DIGIPIN algorithm - Apache 2.0

GitHub: https://github.com/rajatguptaa/digipinjs


🌟 What’s Next?

  • 🔲 React-based map UI component

  • 🔄 REST API / hosted encode-decode microservice

  • 📲 Mobile SDK (React Native)

  • 🎓 Blog series on geolocation systems for India

If you’ve got ideas, questions, or want to integrate this in your app - I’d love to hear from you!


❤️ Made for India’s Developer Community

If you've ever dealt with inconsistent location data in India - digipinjs might save you hours of pain.
Give it a spin, star it, and share feedback - every suggestion counts.

👉 Try it on npm
👉 View the source on GitHub

0
Subscribe to my newsletter

Read articles from Rajat Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rajat Gupta
Rajat Gupta