This content originally appeared on Twilio Blog and was authored by Sam Agnew
While the Twilio Messaging API won't charge you for attempting to send an SMS to a landline number, identifying the line type of a phone number can be useful for other reasons. A lot of businesses won't let users sign up with VoIP numbers, for example.
Let's walk through how to identify a phone number's line type with Twilio Lookup and Node.js.
Setting up
For this post you will need:
- Node.js and npm installed (do this first if you haven't already)
- A free Twilio account
- The Twilio Node library
To install the Twilio npm module, navigate to the directory where you want this code to live and navigate to the directory where you want this code to live and run the following command in your terminal to create a package for this project:
npm init --yes
The --yes
argument just runs through all of the prompts that you would otherwise have to fill out or skip. Now that we have a package.json
for our app, let’s install the Twilio module with the following shell command:
npm install twilio@3.84.0 --save
After this you should be good to write some code!
Looking up the line type with Twilio
You can query the Twilio Lookup API for information about a phone number. There are several types of requests the API can perform including line-type-intelligence
, sim-swap
, and caller-name
. This example focuses on line type intelligence. With the information we get back from this lookup, we can figure out if the phone number is landline, mobile, voip, or another type..
All you need to do a line type lookup in JavaScript is the following code:
// Set environment variables for your Account Sid and Auth Token!
// These can be found at twilio.com/console
const client = require('twilio')();
client.lookups.v2
.phoneNumbers("+18557477626")
.fetch({ fields: 'line_type_intelligence' })
.then((pn) => {
console.log(pn.lineTypeIntelligence); // All of the carrier info.
console.log(pn.lineTypeIntelligence.type); // Just the number's line type.
});
Save that to a file called lookup.js
.
Before running this code, make sure to grab your Account SID and Auth Token from your Twilio Console, and save them as environment variables named TWILIO_ACCOUNT_SID
and TWILIO_AUTH_TOKEN
, which the Twilio Node library will use when you run your code.
After setting these environment variables, run your code using the following command:
node lookup.js
The possible values for line type include mobile
, landline
, or fixedVoip
, nonFixedVoip
, tollFree
, voicemail
, and more. You can see that the line type for our example number, 1 (855) 747-7626, is nonFixedVoip
because it is a Twilio phone number.
Try running the code again with your own phone number and see what comes back!
What's Next
You can add this code to your Express app, or maybe you want to prompt customers to add SMS (or voice!) based 2FA, clean up your database, or segment your users. You may also be interested in validating phone numbers with Node.js or identifying unknown numbers using a name lookup.
Feel free to reach out and share your experiences or ask any questions.
- Email: sagnew@twilio.com
- Twitter: @Sagnewshreds
- Github: Sagnew
- Twitch (streaming live code): Sagnewshreds
This content originally appeared on Twilio Blog and was authored by Sam Agnew

Sam Agnew | Sciencx (2019-12-06T21:54:41+00:00) Identifying Phone Number Line Types with Twilio Lookup and Node.js. Retrieved from https://www.scien.cx/2019/12/06/identifying-phone-number-line-types-with-twilio-lookup-and-node-js/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.