Q:

TypeError: Cannot read property 'isTTY' of undefined

const accountSid = 'account_sid';
const authToken = 'auth_token';

const client = require('twilio')(accountSid, authToken);

client.messages
.create({
    to: '+94716220786',
    from: '+13022519234',
    body: 'Your verification code is ' + Math.floor(1000 + Math.random() * 
9000)
})
.then(message => console.log(message.sid));
console.log('receive');
console.log(Math.floor(1000 + Math.random() * 9000));

I'm trying to send sms using twilio. I have installed twilio latest version in my angular project. 

But when the project runs, it says that "Cannot read property 'isTTY' of undefined"

A:

Twilio developer evangelist here.
The Twilio Node library is not designed to be used on the client side. Mainly because that would expose your credentials and an attacker could then use your account. JavaScript is also editable on the client side, so sending a verification code could easily be edited and abused by an unscrupulous user.
Instead, you need to build a server side component that will make the requests for your client side. If you are building phone verification, then can I recommend you follow this tutorial on account verification with Twilio.
If you want to start a bit more basic, then I recommend the quick start guide to sending and receiving SMS with Twilio in Node.

