SharpAPI.com Node.js SDK for detecting addresses in text
npm install @sharpapi/sharpapi-node-detect-address

SharpAPI Address Detector parses text content and extracts any physical addresses found within. Perfect for data validation, content moderation, and location extraction from unstructured text.
---
1. Requirements
2. Installation
3. Usage
4. API Documentation
5. Examples
6. License
---
- Node.js >= 16.x
- npm or yarn
---
``bash`
npm install @sharpapi/sharpapi-node-detect-address
Visit SharpAPI.com to get your API key.
---
`javascript
const { SharpApiDetectAddressService } = require('@sharpapi/sharpapi-node-detect-address');
const apiKey = process.env.SHARP_API_KEY; // Store your API key in environment variables
const service = new SharpApiDetectAddressService(apiKey);
const text =
Please send all correspondence to our headquarters at 123 Main Street,
Suite 400, New York, NY 10001. Our European office is located at
456 Oxford Street, London W1C 1AP, United Kingdom.;
async function detectAddresses() {
try {
// Submit detection job
const statusUrl = await service.detectAddress(text);
console.log('Job submitted. Status URL:', statusUrl);
// Fetch results (polls automatically until complete)
const result = await service.fetchResults(statusUrl);
console.log('Detected addresses:', result.getResultJson());
} catch (error) {
console.error('Error:', error.message);
}
}
detectAddresses();
`
---
#### detectAddress(text: string): Promise
Detects and extracts addresses from the provided text.
Parameters:
- text (string, required): The text content to scan for addresses
Returns:
- Promise
Example:
`javascript`
const statusUrl = await service.detectAddress(textWithAddresses);
const result = await service.fetchResults(statusUrl);
The API returns detected addresses in a structured format:
`json`
{
"addresses": [
{
"address": "123 Main Street, Suite 400, New York, NY 10001",
"confidence": 0.95,
"components": {
"street": "123 Main Street",
"suite": "Suite 400",
"city": "New York",
"state": "NY",
"postal_code": "10001",
"country": "United States"
}
}
]
}
---
`javascript
const { SharpApiDetectAddressService } = require('@sharpapi/sharpapi-node-detect-address');
const service = new SharpApiDetectAddressService(process.env.SHARP_API_KEY);
const sampleText =
Contact us at our office: 789 Tech Boulevard, San Francisco, CA 94105.
For shipping inquiries: 321 Warehouse Lane, Austin, TX 78701.;
service.detectAddress(sampleText)
.then(statusUrl => service.fetchResults(statusUrl))
.then(result => {
const addresses = result.getResultJson();
console.log(Found ${addresses.length} addresses:);${index + 1}. ${addr.address}
addresses.forEach((addr, index) => {
console.log();`
});
})
.catch(error => console.error('Detection failed:', error));
`javascript
const service = new SharpApiDetectAddressService(process.env.SHARP_API_KEY);
// Customize polling behavior
service.setApiJobStatusPollingInterval(5); // Poll every 5 seconds
service.setApiJobStatusPollingWait(120); // Wait up to 2 minutes
const statusUrl = await service.detectAddress(text);
const result = await service.fetchResults(statusUrl);
`
---
- Data Validation: Extract and validate addresses from user-submitted forms
- Content Moderation: Detect addresses in user-generated content where they shouldn't be
- Location Extraction: Parse unstructured text to extract location information
- Document Processing: Extract addresses from scanned documents or PDFs (after OCR)
- Lead Generation: Extract business addresses from web content
- Compliance: Identify and remove addresses from public-facing content for privacy
---
POST /content/detect_address`
For detailed API specifications, refer to the main SharpAPI Documentation.
---
- @sharpapi/sharpapi-node-detect-emails - Email detection
- @sharpapi/sharpapi-node-detect-phones - Phone number detection
- @sharpapi/sharpapi-node-detect-urls - URL detection
- @sharpapi/sharpapi-node-client - Full SharpAPI SDK
---
This project is licensed under the MIT License. See the LICENSE.md file for details.
---
- Documentation: SharpAPI.com Documentation
- Issues: GitHub Issues
- Email: contact@sharpapi.com
---
Powered by SharpAPI - AI-Powered API Workflow Automation