Skip to content

DIGIPIN encode/decode library & REST API for India Post geo-addressing system using Node.js and TypeScript

License

Notifications You must be signed in to change notification settings

shivamm-55/digipin-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📍 digipin

digipin is a lightweight npm package that lets you convert between latitude/longitude coordinates and Digital Postal Index Numbers (DIGIPINs).

DIGIPIN is a geo-coded addressing system introduced by the Department of Posts, Government of India, aimed at creating a standardized digital address for every location.

🔗 Official DIGIPIN Page:
👉 https://www.indiapost.gov.in/vas/Pages/digipin.aspx


✨ Features

  • 🌍 Convert Latitude & Longitude → DIGIPIN
  • 🔁 Convert DIGIPIN → Latitude & Longitude
  • 📦 Optional REST API (Node.js + Express + TypeScript)
  • 🧠 Fully TypeScript-supported
  • ⚡ Lightweight, fast, and dependency-friendly

📦 Installation

npm install digipin

🚀 Usage (Library)

📌 Named Imports

import { getDIGIPINFromLatLon, getLatLonFromDIGIPIN, getBoundsFromDIGIPIN } from 'digipin';

const digipin = getDIGIPINFromLatLon(12.34, 56.78);
console.log(digipin);

const coordinates = getLatLonFromDIGIPIN('G4J-9K4-7L');
console.log(coordinates);

const bounds = getBoundsFromDIGIPIN('F3M-P6T-FCJK');
console.log(bounds);
// { minLat, maxLat, minLon, maxLon }

📌 Default Import

import digipin from 'digipin';

const digipinCode = digipin.getDIGIPINFromLatLon(12.34, 56.78);
console.log(digipinCode);

const coordinates = digipin.getLatLonFromDIGIPIN('G4J-9K4-7L');
console.log(coordinates);

🔌 REST API Support (Optional)

This package also includes an optional REST API built with:

  • Node.js
  • Express
  • TypeScript

⚠️ The REST API is additive and does not affect library usage.


▶️ Run API Locally

npm install
npm run dev

📡 Server runs at:

http://localhost:3000

❤️ Health Check

curl http://localhost:3000/api/digipin/health

Response:

DIGIPIN API is running 🚀

🔗 API Endpoints

1️⃣ Encode: Latitude/Longitude → DIGIPIN

POST /api/digipin/encode

Request Body

{
  "latitude": 28.6139,
  "longitude": 77.2090
}

cURL

curl -X POST http://localhost:3000/api/digipin/encode \
  -H "Content-Type: application/json" \
  -d '{"latitude":28.6139,"longitude":77.2090}'

Response

{
  "digipin": "DP-2861-7720"
}

2️⃣ Decode: DIGIPIN → Latitude/Longitude

POST /api/digipin/decode

Request Body

{
  "digipin": "DP-2861-7720"
}

cURL

curl -X POST http://localhost:3000/api/digipin/decode \
  -H "Content-Type: application/json" \
  -d '{"digipin":"DP-2861-7720"}'

Response

{
  "latitude": 28.61,
  "longitude": 77.2
}

❌ Error Response

Invalid DIGIPIN

{
  "message": "Invalid DIGIPIN provided"
}

🤝 Contributing

Contributions are welcome! 🚀

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Open a Pull Request

📄 License

MIT © Shivam Mishra

About

DIGIPIN encode/decode library & REST API for India Post geo-addressing system using Node.js and TypeScript

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •