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

SharpAPI Email Detector parses text content and extracts any email addresses found within. Perfect for data validation, content moderation, and lead 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-emails
Visit SharpAPI.com to get your API key.
---
`javascript
const { SharpApiDetectEmailsService } = require('@sharpapi/sharpapi-node-detect-emails');
const apiKey = process.env.SHARP_API_KEY; // Store your API key in environment variables
const service = new SharpApiDetectEmailsService(apiKey);
const text =
For support inquiries, please contact support@example.com or sales@example.com.
You can also reach our CEO at john.doe@company.org for partnership opportunities.;
async function detectEmails() {
try {
// Submit detection job
const statusUrl = await service.detectEmails(text);
console.log('Job submitted. Status URL:', statusUrl);
// Fetch results (polls automatically until complete)
const result = await service.fetchResults(statusUrl);
console.log('Detected emails:', result.getResultJson());
} catch (error) {
console.error('Error:', error.message);
}
}
detectEmails();
`
---
#### detectEmails(text: string): Promise
Detects and extracts email addresses from the provided text.
Parameters:
- text (string, required): The text content to scan for email addresses
Returns:
- Promise
Example:
`javascript`
const statusUrl = await service.detectEmails(textWithEmails);
const result = await service.fetchResults(statusUrl);
The API returns detected emails in a structured format:
`json`
{
"emails": [
{
"email": "support@example.com",
"confidence": 1.0,
"domain": "example.com",
"username": "support"
},
{
"email": "john.doe@company.org",
"confidence": 1.0,
"domain": "company.org",
"username": "john.doe"
}
]
}
---
`javascript
const { SharpApiDetectEmailsService } = require('@sharpapi/sharpapi-node-detect-emails');
const service = new SharpApiDetectEmailsService(process.env.SHARP_API_KEY);
const sampleText =
Contact our team at hello@startup.io or reach out to
the marketing department at marketing@startup.io.;
service.detectEmails(sampleText)
.then(statusUrl => service.fetchResults(statusUrl))
.then(result => {
const emails = result.getResultJson();
console.log(Found ${emails.length} email addresses:);${index + 1}. ${email.email}
emails.forEach((email, index) => {
console.log();`
});
})
.catch(error => console.error('Detection failed:', error));
`javascript
const service = new SharpApiDetectEmailsService(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.detectEmails(text);
const result = await service.fetchResults(statusUrl);
`
---
- Lead Generation: Extract email addresses from web pages, documents, or social media
- Data Validation: Verify and extract emails from user-submitted forms
- Content Moderation: Detect email addresses in user-generated content
- Email Harvesting: Collect contact information from business cards or documents
- Spam Detection: Identify suspicious email patterns in text
- Contact Management: Parse unstructured text to build contact databases
---
POST /content/detect_emails`
For detailed API specifications, refer to:
- Postman Documentation
- Product Page
---
- @sharpapi/sharpapi-node-detect-phones - Phone number detection
- @sharpapi/sharpapi-node-detect-urls - URL detection
- @sharpapi/sharpapi-node-detect-address - Address 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