BLACK FRIDAY DEAL!
Get $100 OFF on lifetime access!

Node.js / Express Integration

Integrate PureSignup into your Node.js backend with Express, Fastify, or any other framework.

Installation

No special package needed - use the native fetch API or any HTTP client:

Optional: Install axios
npm install axios

Basic Implementation

PureSignup.js
// Using native fetch (Node 18+)
async function checkEmail(email) {
  try {
    const response = await fetch(
      `https://puresignup.com/api/v1/check?q=${encodeURIComponent(email)}`,
      {
        headers: {
          'Authorization': `Bearer ${process.env.PureSignup_API_KEY}`
        }
      }
    );

    if (!response.ok) {
      throw new Error(`API error: ${response.status}`);
    }

    const data = await response.json();
    return data.data;
  } catch (error) {
    console.error('PureSignup check failed:', error);
    return null; // Fail open
  }
}

module.exports = { checkEmail };

Express.js Middleware

middleware/validateEmail.js
const { checkEmail } = require('../services/PureSignup');

async function validateEmailMiddleware(req, res, next) {
  const email = req.body.email;

  if (!email) {
    return res.status(400).json({ error: 'Email is required' });
  }

  try {
    const result = await checkEmail(email);
    
    if (result && result.risk_level === 'high') {
      return res.status(400).json({
        error: 'Disposable email addresses are not allowed',
        field: 'email'
      });
    }

    // Email is valid, continue
    next();
  } catch (error) {
    // Fail open on error
    console.error('Email validation error:', error);
    next();
  }
}

module.exports = validateEmailMiddleware;

Usage in Routes

routes/auth.js
const express = require('express');
const router = express.Router();
const validateEmail = require('../middleware/validateEmail');
const { createUser } = require('../controllers/user');

router.post('/signup', validateEmail, async (req, res) => {
  try {
    const user = await createUser(req.body);
    res.status(201).json({ user });
  } catch (error) {
    res.status(500).json({ error: 'Signup failed' });
  }
});

module.exports = router;

Next Steps

© 2025 PureSignup. All rights reserved.