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
:
npm install swot-node
Or using yarn
:
yarn add swot-node
Usage
First we import the installed library:
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
:
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:
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 of the library.
Full example
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.
Top comments (2)
When I first looked at this article, I thought it was yet another dependency wrapper for splitting a string and checking for "edu", but that's not the case! Very astute of the maintainers to consider non-US educational institutions that don't have country-specific education domains. I think you should add that into the article, because that's where the value is for me :)
Hi Zach! Many thanks for the suggestion! I have added it to the article.