pincode-info
v1.0.2
Published
A simple NPM package to get city and post office details by pincode or branch name in India
Downloads
57
Maintainers
Readme
pincode-info
A simple NPM package to get city and post office details by pincode or branch name in India using the India Post API.
Documentation / References
Installation
npm install pincode-infoUsage
Get City by Pincode
const { getCityByPincode, getPostOfficeDetails } = require("pincode-info");
// Get city details by pincode
getCityByPincode("110001")
.then((city) => console.log("City by Pincode:", city))
.catch((err) => console.error(err));Get Post Office Details by Branch Name
const { getCityByPincode, getPostOfficeDetails } = require("pincode-info");
// Get post office details by branch name
getPostOfficeDetails("Connaught Place")
.then((postOffice) => console.log("Post Office Details:", postOffice))
.catch((err) => console.error(err));API Reference
getCityByPincode(pincode)
Get post office details by 6-digit Indian postal code.
Parameters:
pincode(string) – the 6-digit Indian postal code
Returns:
- Promise that resolves to an array of post offices with the following details:
name– Post Office namedistrict– District namestate– State namecountry– Country
Example:
const { getCityByPincode } = require("pincode-info");
getCityByPincode("110001")
.then((postOffices) => console.log("Post Offices:", postOffices))
.catch((err) => console.error(err));getPostOfficeDetails(branchName)
Get post office details by branch name.
Parameters:
branchName(string) – name of the Post Office branch
Returns:
- Promise that resolves to an array of post offices with the following details:
name– Post Office namedistrict– District namestate– State namepincode– Pincodecountry– CountrybranchType– Type of Post Office
Example:
const { getPostOfficeDetails } = require("pincode-info");
getPostOfficeDetails("Connaught Place")
.then((postOffice) => console.log("Post Office Details:", postOffice))
.catch((err) => console.error(err));Complete Usage Example
const { getCityByPincode, getPostOfficeDetails } = require("pincode-info");
// Get all post offices in a pincode area
getCityByPincode("110001")
.then((postOffices) => {
console.log("Post offices in 110001:");
postOffices.forEach((office) => {
console.log(`- ${office.name}, ${office.district}, ${office.state}`);
});
})
.catch(console.error);
// Get specific post office details
getPostOfficeDetails("Connaught Place")
.then((offices) => {
if (offices.length > 0) {
const office = offices[0];
console.log(`Pincode: ${office.pincode}`);
console.log(`Branch Type: ${office.branchType}`);
console.log(`Location: ${office.district}, ${office.state}`);
}
})
.catch(console.error);Example Output:
{
"Name": "Aliganj",
"Description": null,
"BranchType": "Sub Post Office",
"DeliveryStatus": "Non-Delivery",
"Circle": "Bihar",
"District": "Bhagalpur",
"Division": "Bhagalpur",
"Region": "Patna HQ",
"Block": "Jagdishpur",
"State": "Bihar",
"Country": "India",
"Pincode": "812005"
},