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
- 🌍 Convert Latitude & Longitude → DIGIPIN
- 🔁 Convert DIGIPIN → Latitude & Longitude
- 📦 Optional REST API (Node.js + Express + TypeScript)
- 🧠 Fully TypeScript-supported
- ⚡ Lightweight, fast, and dependency-friendly
npm install digipinimport { 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 }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);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.
npm install
npm run dev📡 Server runs at:
http://localhost:3000
curl http://localhost:3000/api/digipin/healthResponse:
DIGIPIN API is running 🚀
POST /api/digipin/encode
{
"latitude": 28.6139,
"longitude": 77.2090
}curl -X POST http://localhost:3000/api/digipin/encode \
-H "Content-Type: application/json" \
-d '{"latitude":28.6139,"longitude":77.2090}'{
"digipin": "DP-2861-7720"
}POST /api/digipin/decode
{
"digipin": "DP-2861-7720"
}curl -X POST http://localhost:3000/api/digipin/decode \
-H "Content-Type: application/json" \
-d '{"digipin":"DP-2861-7720"}'{
"latitude": 28.61,
"longitude": 77.2
}Invalid DIGIPIN
{
"message": "Invalid DIGIPIN provided"
}Contributions are welcome! 🚀
- Fork the repository
- Create a feature branch
- Commit your changes
- Open a Pull Request
MIT © Shivam Mishra