Look Up a Phone Number in Node.js with Twilio

Joe Previte
InstructorJoe Previte

Share this video with your friends

Send Tweet
Published 4 years ago
Updated 4 years ago

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.

Instructor: [00:00] 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.

[00:19] 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.

[00:32] 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.

[00:52] 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.

[01:13] 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.

[01:25] 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.

[01:47] Cool. We got a response. You should see the phone number and more information about that number.