19

How to verify school email addresses in Node.js

 3 years ago
source link: https://dev.to/magicmarvman/how-to-verify-school-email-addresses-in-node-js-2675
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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.

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
Enter fullscreen modeExit fullscreen mode

Or using yarn:

yarn add swot-node
Enter fullscreen modeExit fullscreen mode

Usage

First we import the installed library:

const swot = require("swot-node");
Enter fullscreen modeExit fullscreen mode

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("[email protected]").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!");
    }
});
Enter fullscreen modeExit fullscreen mode

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

swot.getSchoolNames("[email protected]").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' ]
    }
});
Enter fullscreen modeExit fullscreen mode

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("[email protected]").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("[email protected]").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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK