Look up a number with Node.js

You can quickly see how the Number Lookup API works by looking up a number using the API.

In this guide you will learn how to:

Learn how to:
  1. Set up your Node.js application
  2. Look up your phone number

What you need to know before you start

Before you can get started, you need the following already set up:

Set up your Node.js application

First we'll create a Node project using npm.

To create the project, do the following steps:

  1. Create a folder called number-lookup.
  2. Navigate into the folder you created and run the following command.
    Copy
    Copied
    npm init

    This command creates the package.json file. You will be prompted to provide values for the fields. For this tutorial, you can simply accept the default values and press enter at each stage.

  3. Add the fetch package with npm to generate the necessary dependencies.
Copy
Copied
npm install 'cross-fetch'

Create your file

Create a new file named index.js in the project and paste the provided "index.js" code into the file.

Note:

This tutorial uses basic authentication for testing purposes. We recommend using a signed request for authentication in a production environment. You can follow the steps in this guide, but use the code samples from here to use request signing authentication instead.

Fill in your parameters

Assign your values to the following parameters:

ParameterYour value
APPLICATION_KEYThe key found on your Sinch dashboard.
APPLICATION_SECRETThe secret found on your Sinch dashboard.
NUMBERThe phone number that you want to look up in E.164 format.

Save the file.

Look up your phone number

Now you can execute the code and look up your phone number. Run the following command:

Copy
Copied
node index.js

You should receive a response in your console with details about the phone number you specified.

Troubleshooting tip

If after running your app you receive a 5000 error response, you may have forgotten to save your file after adding your authentication values. This is an easy mistake to make! Try saving the file and running the app again.

Additional resources

We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.