3

Example

isPersonalEmail("name@gmail.com") // true
isPersonalEmail("name@companyName.com") // false

I can't find NPM package do that I need to check email in node.js server

1 Answers1

4

I found two npm packages that you can use to achieve that:

Free Email Domains by Kiko Beats

The package is based on HubSpot-blocked domains

Email Providers by derhuerst

Provides the same solution, with the advantage of having the option to use all 4k domains in the list, or the 312 common domains only. he defines common as follows:

common.json contains those with an Majestic Million rank of < 100000.


Full Solution

I also stumbled upon a relevant issue that you might want to consider when you extract the domain.

const emailProviders = require("email-providers/all.json")
const parser = require('tld-extract');
const validator = require('validator');

const companyEmail = "name@companyName.com"
const personalEmail = "name@gmail.com"
const personalEmailWithSubdomain = "name@abc.gmail.com"

// 1. You should validate that the string is an actual email as well
// if (!validator.isEmail(email)) return error or something...

const isPersonalEmail = (email) => {

    // 2. Extract the domain
    const broken = email.split('@')
    const address = `http://${broken[broken.length - 1]}`
    const { domain } = parser(address);

    // 3. And check!
    return emailProviders.includes(domain)
}

console.log(isPersonalEmail(companyEmail)) // false
console.log(isPersonalEmail(personalEmail)) // true
console.log(isPersonalEmail(personalEmailWithSubdomain)) // true
Jassar
  • 306
  • 4
  • 17