The Sinch Node.js SDK allows you to quickly interact with the Number Lookup API from inside your Node.js applications. When using the Node.js SDK, the code representing requests and queries sent to and responses received from the Number Lookup API are structured similarly to those that are sent and received using the Number Lookup API.
The fastest way to get started with the SDK is to check out our getting started guides. There you'll find all the instructions necessary to download, install, set up, and start using the SDK.
This guide describes the syntactical structure of the Node.js SDK for the Number Lookup API, including any differences that may exist between the API itself and the SDK. For a full reference on Number Lookup API calls and responses, see the Number Lookup API Reference.
This code sample is an example of how to use the Node.js SDK to lookup a specified number. We've also provided an example that accomplishes the same task using the REST API.
// This code looks up a specified number.
/**
* Class to lookup a number through the NumberLookup API using the Sinch Node.js SDK.
*/
export class NumberLookupSample {
/**
* @param { import('@sinch/sdk-core').NumberLookupService } numberLookupService - the NumberLookupService instance from the Sinch SDK containing the API methods.
*/
constructor(numberLookupService) {
this.numberLookupService = numberLookupService;
}
async start() {
// The phone number to lookup in E.164 format
const phoneNumber = 'PHONE_NUMBER_TO_LOOKUP';
const response = await this.numberLookupService.lookup({
numberLookupRequestBody: {
number: phoneNumber,
},
});
console.log('Response:', response);
}
}This example highlights the following required to successfully make a Number Lookup API call using the Sinch Node.js SDK:
When using the Sinch Node.js SDK, you initialize communication with the Sinch backend by initializing the Node.js SDK's main client class. This client allows you to access the the functionality of the Sinch Node.js SDK.
To start using the SDK, you need to initialize the main client class with your credentials from your Sinch dashboard.
const {SinchClient} = require('@sinch/sdk-core');
const sinchClient = new SinchClient({
projectId: "YOUR_project_id",
keyId: "YOUR_access_key",
keySecret: "YOUR_access_secret"
});For testing purposes on your local environment it's fine to use hardcoded values, but before deploying to production we strongly recommend using environment variables to store the credentials, as in the following example:
.env File
PROJECTID="YOUR_project_id"
ACCESSKEY="YOUR_access_key"
ACCESSSECRET="YOUR_access_secret" app.js File
const {SinchClient} = require('@sinch/sdk-core');
const sinchClient = new SinchClient({
projectId: process.env.PROJECTID,
keyId: process.env.ACCESSKEY,
keySecret: process.env.ACCESSSECRET
});The Sinch Node.js SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, sinch.numberLookup().[method()].
In the Sinch Node.js SDK, Number Lookup API endpoints are accessible through the client:
For example:
const response = await sinch.numberLookup.lookup({
numberLookupRequestBody: {
number: phoneNumber,
features: [ 'LineType' ],
},
});Response fields match the API responses. They are delivered as JavaScript objects.



