Node.js Examples
All examples use the built-in fetch API (available in Node.js 18+). Set your API key in the environment:
export VERIFNOW_API_KEY=your_api_key_hereInstallation
No SDK needed — VerifNow works with plain fetch. For TypeScript users, the examples below include type definitions.
# TypeScript types (optional)
npm install --save-dev typescript @types/nodeValidate a single email
JavaScript
// validate-email.js
async function validateEmail(email) {
const response = await fetch('https://api.verifnow.io/api/v1/validate/email', {
method: 'POST',
headers: {
'X-API-KEY': process.env.VERIFNOW_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({ value: email }),
})
if (!response.ok) {
const error = await response.json()
throw new Error(`VerifNow error [${error.error.code}]: ${error.error.message}`)
}
return response.json()
}
// Usage
;(async () => {
const result = await validateEmail('user@example.com')
console.log('Valid:', result.valid)
console.log('Risk level:', result.emailDetails.risk_level)
console.log('Disposable:', result.emailDetails.signals.disposable)
if (result.emailDetails.signals.typo_detected) {
console.log('Suggested domain:', result.emailDetails.signals.suggested_domain)
}
})()Validate email in an Express.js route
// routes/auth.ts
import express from 'express'
const router = express.Router()
router.post('/register', async (req, res) => {
const { email, password } = req.body
// Validate email with VerifNow
let validation
try {
const vnResponse = await fetch('https://api.verifnow.io/api/v1/validate/email', {
method: 'POST',
headers: {
'X-API-KEY': process.env.VERIFNOW_API_KEY!,
'Content-Type': 'application/json',
},
body: JSON.stringify({ value: email }),
})
validation = await vnResponse.json()
} catch (err) {
// Don't block registration if VerifNow is unreachable
console.error('VerifNow unavailable, skipping validation:', err)
validation = { valid: true }
}
if (!validation.valid) {
return res.status(400).json({
error: 'Please provide a valid email address.',
suggestion: validation.emailDetails?.signals?.suggested_domain ?? undefined,
})
}
if (validation.emailDetails?.signals?.disposable) {
return res.status(400).json({
error: 'Disposable email addresses are not allowed.',
})
}
// Continue with user creation...
res.json({ success: true, email })
})
export default routerNext.js App Router API route
// app/api/validate-email/route.ts
import { NextRequest, NextResponse } from 'next/server'
export async function POST(req: NextRequest) {
const body = await req.json()
const { value } = body
if (!value || typeof value !== 'string') {
return NextResponse.json(
{ error: 'value is required' },
{ status: 400 }
)
}
const response = await fetch('https://api.verifnow.io/api/v1/validate/email', {
method: 'POST',
headers: {
'X-API-KEY': process.env.VERIFNOW_API_KEY!,
'Content-Type': 'application/json',
},
body: JSON.stringify({ value }),
})
const data = await response.json()
return NextResponse.json(data, { status: response.status })
}Reusable VerifNow client class
// lib/verifnow.ts
class VerifNow {
private apiKey: string
private baseUrl: string
constructor(apiKey: string, baseUrl = 'https://api.verifnow.io/api/v1/validate') {
this.apiKey = apiKey
this.baseUrl = baseUrl
}
private async request<T>(path: string, value: string): Promise<T> {
const response = await fetch(`${this.baseUrl}${path}`, {
method: 'POST',
headers: {
'X-API-KEY': this.apiKey,
'Content-Type': 'application/json',
},
body: JSON.stringify({ value }),
})
const data = await response.json()
if (!response.ok) {
throw new Error(`VerifNow [${data.error?.code}]: ${data.error?.message}`)
}
return data
}
validateEmail(email: string) {
return this.request<ValidationResult>('/email', email)
}
validatePhone(phone: string) {
return this.request<ValidationResult>('/phone', phone)
}
}
export const verifnow = new VerifNow(process.env.VERIFNOW_API_KEY!)
// Usage
const result = await verifnow.validateEmail('user@example.com')Bulk (batch) validation is not yet available. For now, validate one item at a time.
Last updated on