How to verify school email addresses in Node.js
Tags: node, javascript, howto, tutorial
Published: 2021-02-13 17:50:14

**In this post, we look at how school email addresses can be verified easily and quickly in Node.js.**

This is especially useful when a service wants to give certain perks or benefits to students or teachers. Often this is done using paid enterprise service providers, but in the vast majority of cases, verification can also be done quickly and free of charge using the user's email address.

Unfortunately, one disadvantage of most modules for checking school emails is that they only check if the domain ends in ".edu", which eliminates all international educational institutions as they cannot use an ".edu" domain.  

The module used in this article is based on the Jetbrains dataset, which contains thousands of international educational institutions and is constantly growing.  

_**Disclaimer:** I am the developer of the module mainly used in this post._

## Requirements

The only requirement to verify a user's student status is a confirmed email address (or more precisely, domain of the email address, for example) of the user.

## Installation

The installation of the required modules in an already initialised and set up Node.js project can easily be done with `npm`:

```bash
npm install swot-node
```

Or using `yarn`:

```bash
yarn add swot-node
```

## Usage

First we import the installed library:

```javascript
const swot = require("swot-node");
```

After that, the use is very simple. Any URL containing a domain can be entered as input. This does not necessarily have to be an email address, but it makes the most sense when verifying students, for example.

The use is asynchronous via Promises or `async` / `await`:

```javascript
swot.isAcademic("example@stanford.edu").then((response) => {
	if (response) {
		// The email belongs to an educational institution!
		console.log("The email belongs to an educational institution!");
	} else {
		// The email does not belong to an educational institution!
		console.log("The email does not belong to an educational institution!");
	}
});
```

It is also possible to get the name(s) of the educational institution:

```javascript
swot.getSchoolNames("example@stanford.edu").then((response) => {
	if (response === false) {
		// URL does not belong to an academic institution
		console.log("URL does not belong to an academic institution");
	} else if (response === true) {
		// URL ends on a TLD reserved for academic institutions, but has no entry of its own in the database
		console.log(
			"URL ends on a TLD reserved for academic institutions, but has no entry of its own in the database"
		);
	} else {
		// Domain has an entry and there are also names in the database
		console.log(response);
		// => [ 'Stanford University' ]
	}
});
```

The exact possible return values of the functions can be found in the [documentation](https://swot.js.org) of the library.

## Full example
```javascript
const swot = require("swot-node");


// Just check if email belongs to an academic institution
swot.isAcademic("example@stanford.edu").then((response) => {
	if (response) {
		// The email belongs to an educational institution!
		console.log("The email belongs to an educational institution!");
	} else {
		// The email does not belong to an educational institution!
		console.log("The email does not belong to an educational institution!");
	}
});

// Check if email belongs to an academic institution and get name(s) of institution
swot.getSchoolNames("example@stanford.edu").then((response) => {
	if (response === false) {
		// URL does not belong to an academic institution
		console.log("URL does not belong to an academic institution");
	} else if (response === true) {
		// URL ends on a TLD reserved for academic institutions, but has no entry of its own in the database
		console.log(
			"URL ends on a TLD reserved for academic institutions, but has no entry of its own in the database"
		);
	} else {
		// Domain has an entry and there are also names in the database
		console.log(response);
		// => [ 'Stanford University' ]
	}
});
```

## Conclusion
To check in Node.js whether an email address belongs to a student, it is not necessary to use a paid commercial service.  

Instead, you can simply use free open source software, which is maintained by the community and thus also guarantees a much larger and higher quality data set.  

More about the library `swot-node` can be found in the [documentation](https://swot.js.org).