<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rajat Gupta</title>
    <description>The latest articles on DEV Community by Rajat Gupta (@rajat).</description>
    <link>https://dev.to/rajat</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F214856%2F95a4555d-af0e-411f-bf81-f07e8433cb47.png</url>
      <title>DEV Community: Rajat Gupta</title>
      <link>https://dev.to/rajat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rajat"/>
    <language>en</language>
    <item>
      <title>Introducing digipinjs: India’s Digital Postal Index Number (DIGIPIN) Library</title>
      <dc:creator>Rajat Gupta</dc:creator>
      <pubDate>Sat, 21 Jun 2025 11:23:07 +0000</pubDate>
      <link>https://dev.to/rajat/introducing-digipinjs-indias-digital-postal-index-number-digipin-library-23ba</link>
      <guid>https://dev.to/rajat/introducing-digipinjs-indias-digital-postal-index-number-digipin-library-23ba</guid>
      <description>&lt;p&gt;India’s Department of Posts (Govt of India) has launched &lt;strong&gt;DIGIPIN&lt;/strong&gt; – an open-source, nationwide geo-coded addressing system.  DIGIPIN assigns a &lt;em&gt;unique 10-character alphanumeric code&lt;/em&gt; to every ~4×4 m grid in India.  In other words, each small geographic cell gets its own “digital PIN”, derived from its latitude/longitude.  Unlike traditional 6-digit PIN codes that cover broad areas, a DIGIPIN code &lt;em&gt;pinpoints the exact location of a property&lt;/em&gt;.  For example, DIGIPIN codes are precise down to ~4 m squares, making them ideal for e-commerce deliveries, emergency services, navigation, and any application needing accurate geolocation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why DIGIPIN Matters
&lt;/h2&gt;

&lt;p&gt;DIGIPIN bridges India’s physical addresses and their digital representation.  It is designed to improve last-mile delivery and address management.  Key benefits include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Exact location accuracy:&lt;/strong&gt; Each DIGIPIN corresponds to a ~4 × 4 m grid, ensuring precise positioning (much finer than area-based PINs).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Streamlined services:&lt;/strong&gt; By encoding precise coordinates, DIGIPIN helps logistics and delivery companies avoid errors.  Online shoppers and delivery platforms (e.g. Amazon, Flipkart) can use DIGIPIN codes to ensure quick, accurate deliveries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Emergency response:&lt;/strong&gt; Ambulances, police, and firefighters can use DIGIPIN to reach exact sites faster, reducing response times.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inclusivity &amp;amp; Standardization:&lt;/strong&gt; DIGIPIN works everywhere in India (urban or remote) and provides an extra &lt;em&gt;Address-as-a-Service&lt;/em&gt; layer, helping areas with unstructured or no traditional addresses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Privacy:&lt;/strong&gt; A DIGIPIN encodes &lt;em&gt;only&lt;/em&gt; location – no personal data is stored or required.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short, DIGIPIN supports modern services and a digital transformation of India’s address system.  It is open-source and interoperable, enabling easy integration with web, mobile, GIS and emergency-response systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview of &lt;em&gt;digipinjs&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;digipinjs&lt;/strong&gt; is a comprehensive &lt;strong&gt;TypeScript library&lt;/strong&gt; for the DIGIPIN system.  It provides developers with simple functions and tools to convert between geographic coordinates (latitude/longitude) and DIGIPIN codes.  Core capabilities include: encoding lat/lng to DIGIPIN and decoding a DIGIPIN back to coordinates.  It also includes validation (ensuring coordinates are within India’s bounds) and clear error handling when inputs are invalid.&lt;/p&gt;

&lt;p&gt;Key highlights of the &lt;em&gt;digipinjs&lt;/em&gt; library:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Official Geocoding Support:&lt;/strong&gt; Implements the government-defined DIGIPIN algorithm, covering India’s latitudes (2.5°N–38.5°N) and longitudes (63.5°E–99.5°E).  You can trust it to follow the official 10-char code format and character set.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Full TypeScript Support:&lt;/strong&gt; Written in TypeScript with complete type definitions, making it safe and easy to use in modern JS/TS projects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lightweight &amp;amp; Fast:&lt;/strong&gt; Optimized for performance with minimal overhead. The underlying code is similar to the official Node.js API and is designed for speed and low memory (using an LRU cache for repeated lookups).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CLI Tool:&lt;/strong&gt; A command-line interface (&lt;code&gt;digipin-cli&lt;/code&gt;) lets you quickly encode/decode coordinates without writing code. Useful for one-off conversions or scripting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Batch Processing &amp;amp; Caching:&lt;/strong&gt; Process lists of locations efficiently and cache recent results to speed up repeated queries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Express Middleware:&lt;/strong&gt; Built-in middleware for Express.js can automatically add DIGIPIN info to HTTP responses or requests, enabling seamless integration in web apps and APIs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grid Generation &amp;amp; Reverse Geocoding:&lt;/strong&gt; Functions to generate offline DIGIPIN grids or reverse-geocode (convert DIGIPIN → lat/lng) are included.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross-Sector Ready:&lt;/strong&gt; By adopting DIGIPIN via this library, your application aligns with a cross-sector digital address standard used in e-commerce, logistics, BFSI (banking/finance), governance, and more.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Install via your favorite package manager:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;npm:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  npm &lt;span class="nb"&gt;install &lt;/span&gt;digipinjs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;yarn:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  yarn add digipinjs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;pnpm:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  pnpm add digipinjs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Using the CLI
&lt;/h3&gt;

&lt;p&gt;After installation, the CLI tool makes it easy to encode or decode locations from the command line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Encode coordinates (latitude, longitude) to DIGIPIN&lt;/span&gt;
npx digipin-cli encode &lt;span class="nt"&gt;--lat&lt;/span&gt; 28.6139 &lt;span class="nt"&gt;--lng&lt;/span&gt; 77.2090
&lt;span class="c"&gt;# Example output: 39J-438-TJC7&lt;/span&gt;

&lt;span class="c"&gt;# Decode a DIGIPIN back to coordinates&lt;/span&gt;
npx digipin-cli decode &lt;span class="nt"&gt;--pin&lt;/span&gt; 39J-438-TJC7
&lt;span class="c"&gt;# Output: Latitude: 28.613901°, Longitude: 77.208998°&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also enable verbose mode or change output format (e.g. DMS coordinates) via additional flags.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using the Library in Code
&lt;/h3&gt;

&lt;p&gt;Import the library functions and use them in your TypeScript or JavaScript code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getDigiPin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;getLatLngFromDigiPin&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;digipinjs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Encode coordinates to DIGIPIN&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;delhiPin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getDigiPin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;28.6139&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;77.2090&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Delhi DIGIPIN: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;delhiPin&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// e.g. "39J-438-TJC7"&lt;/span&gt;

&lt;span class="c1"&gt;// Decode DIGIPIN to coordinates&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;coords&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getLatLngFromDigiPin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;39J-438-TJC7&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;coords&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// { latitude: 28.613901, longitude: 77.208998 }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For batch conversions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;batchEncode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;batchDecode&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;digipinjs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;locations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;lat&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;19.0760&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;lng&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;72.8777&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;  &lt;span class="c1"&gt;// Mumbai&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;lat&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;12.9716&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;lng&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;77.5946&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;  &lt;span class="c1"&gt;// Bengaluru&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;batchEncode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;locations&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pins&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// e.g. ["4FK-595-8823", "2L7-3K9-8P2F"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Integrating with Express is straightforward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;digiPinMiddleware&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;digipinjs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;digiPinMiddleware&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="c1"&gt;// The middleware adds an `X-DIGIPIN` header (or similar) based on request coordinates&lt;/span&gt;

&lt;span class="c1"&gt;// ... define routes ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The library also exports helper functions like &lt;code&gt;getCached&lt;/code&gt;/&lt;code&gt;setCached&lt;/code&gt; (LRU caching), &lt;code&gt;reverseGeocode&lt;/code&gt;, etc., giving you full programmatic control.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example Use Cases
&lt;/h2&gt;

&lt;p&gt;Developers and businesses in many domains can benefit from &lt;em&gt;digipinjs&lt;/em&gt; and DIGIPIN:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;E-commerce &amp;amp; Delivery:&lt;/strong&gt; Encode customer or warehouse locations to DIGIPIN to improve delivery routing and tracking. For example, an online store can store DIGIPIN codes for addresses to reduce misdeliveries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real Estate / Maps:&lt;/strong&gt; Store a property’s DIGIPIN to give a precise location code for listings or map services.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Emergency Services:&lt;/strong&gt; Enable 911/112 services to quickly locate callers via DIGIPIN. First responders can use the code to find victims faster.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Government &amp;amp; NGOs:&lt;/strong&gt; Use DIGIPIN in census, social services, and disaster relief to identify precise locations even in rural or informal settlements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Banking &amp;amp; KYC:&lt;/strong&gt; Banks and insurers can attach DIGIPIN to customer records for precise address verification in KYC processes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smart Cities / GIS:&lt;/strong&gt; Integrate into mapping systems or smart-city dashboards as a standard location identifier.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In essence, &lt;em&gt;digipinjs&lt;/em&gt; makes it easy to adopt DIGIPIN anywhere: from personal scripting to large-scale enterprise applications. By encoding lat/long to a compact, human-friendly code (e.g. &lt;code&gt;FC9-8J3-27K4&lt;/code&gt;), it simplifies address management and aligns with India’s national geospatial initiatives.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Help &amp;amp; Contributing
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;digipinjs&lt;/em&gt; is open-source. The core algorithm and reference code are public domain (originally from CEPT-VZG/India Post) and the library is MIT-licensed. You can view the source on GitHub, report issues, or contribute improvements.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Repository:&lt;/strong&gt; &lt;a href="https://github.com/rajatguptaa/digipinjs" rel="noopener noreferrer"&gt;github.com/rajatguptaa/digipinjs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Issues &amp;amp; Discussions:&lt;/strong&gt; Use GitHub Issues/Discussions for questions or feature requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;License:&lt;/strong&gt; MIT for the wrapper; the underlying DIGIPIN code is Apache 2.0 (per India Post’s open-source release).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;With &lt;strong&gt;digipinjs&lt;/strong&gt;, any JavaScript or TypeScript project can leverage India’s official DIGIPIN system. It provides a full toolset (code library, CLI, middleware) to encode/decode precise digital addresses easily. By using digipinjs, developers align with India Post’s vision of &lt;strong&gt;“Address as a Service”&lt;/strong&gt; and help build a more efficient, error-free delivery and emergency response network.&lt;/p&gt;

&lt;p&gt;Whether you’re a logistics developer, data scientist, or hobbyist building a mapping app, digipinjs streamlines working with India’s geographic addressing. Try it out to add DIGIPIN support to your projects and join the move toward precise, digital-first address systems in India.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References:&lt;/strong&gt; Government of India (India Post) and news media on DIGIPIN.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
