Skip to main content

Overview

The Vouch Node.js SDK enables server-side email validation with higher rate limits and no domain restrictions. Perfect for backend APIs, serverless functions, and batch processing.
Package: @vouch/node Node Version: 14+ required TypeScript: Full type definitions included

Installation

npm install @vouch/node

Quick Start

import { Vouch } from '@vouch/node';

// Initialize with server API key
const vouch = new Vouch(
  process.env.VOUCH_PROJECT_ID,
  process.env.VOUCH_SERVER_KEY
);

// Validate an email (server-side, no device fingerprint)
const result = await vouch.validate('[email protected]');

// Or with optional fingerprint from client and request context
const resultWithContext = await vouch.validate(
  '[email protected]',
  clientFingerprint, // Fingerprint object from client SDK
  {
    ip: req.ip,
    userAgent: req.headers['user-agent']
  }
);

if (!result.success) {
  throw new Error(result.error || 'Validation failed');
}

if (result.data && !result.data.checks.syntax?.pass) {
  throw new Error('Invalid email format');
}

Express.js Integration

import express from 'express';
import { Vouch } from '@vouch/node';

const app = express();
const vouch = new Vouch(PROJECT_ID, SERVER_KEY);

app.post('/api/signup', async (req, res) => {
  const { email } = req.body;

  try {
    const result = await vouch.validate(
      email,
      undefined, // No client fingerprint
      {
        ip: req.ip,
        userAgent: req.get('user-agent')
      }
    );

    if (!result.success) {
      return res.status(result.statusCode || 400).json({
        error: result.error || 'Validation failed'
      });
    }

    if (result.data) {
      const { checks } = result.data;

      // Check critical validations
      if (!checks.syntax?.pass || !checks.disposable?.pass) {
        return res.status(400).json({
          error: 'Email address cannot be used'
        });
      }
    }

    // Create user
    const user = await createUser(email);

    res.json({ success: true, user });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

Serverless Functions

AWS Lambda

import { Vouch } from '@vouch/node';

const vouch = new Vouch(
  process.env.VOUCH_PROJECT_ID,
  process.env.VOUCH_SERVER_KEY
);

export const handler = async (event) => {
  const { email } = JSON.parse(event.body);

  const result = await vouch.validate(email);

  return {
    statusCode: 200,
    body: JSON.stringify(result)
  };
};

Vercel

import { Vouch } from '@vouch/node';

const vouch = new Vouch(
  process.env.VOUCH_PROJECT_ID,
  process.env.VOUCH_SERVER_KEY
);

export default async function handler(req, res) {
  const { email } = req.body;

  const result = await vouch.validate(email);

  res.status(200).json(result);
}

Server vs Client Keys

Always use server keys on the backend. Never expose server keys in client-side code!
Server Key Benefits:
  • No domain restrictions
  • Higher rate limits (5,000/hour vs 1,000/hour)
  • Can override IP and User-Agent
  • Full access to all features

Next Steps