Look Up a Phone Number in Node.js with Twilio

Joe Previte
InstructorJoe Previte
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 5 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.

~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today