Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Look Up a Phone Number in Node.js with Twilio

    Joe PreviteJoe Previte

    In this lesson, you will learn how to look up a phone number in Node.js with Twilio's. We will utilize Twilio's Lookup API which allows lookup and verify any number.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    Instructor: The first thing we're going to do is install our dependencies. We're going to run npm install --save twilio.env. Next, we're going to set up our .env file based off of the .env that example file.

    We're going to be using these environment variables, your account sid which will find in this Twilio Console, your authorization token also from this variable console, and the phone number we're going to be working with.

    After we sign up for account with Twilio, you can find your account sid here on the right side in the console and also your authorization token. After you've added any environment variables inside of the .env file, you can head back to the index.js file.

    Notice, how we're initializing the Twilio Helper Library by creating a variable called clients, which will use interact with the Lookup API. We're going to call client.lookups to use the LookupsAPI.phonenumbers. Then, we're going to pass in process.env.phonenumber.

    This will be the phone number that we're going to interact with. Next, we're going to call .fetch and pass in an object with the country code that we want the number formatted in.

    Since this returns a promise, we can call .then and return the data as phone number and console log it. Last, we can call .turn to let Twilio know that we are done. Now, let's test it out by running node index.js.

    Cool. We got a response. You should see the phone number and more information about that number.