Sending SMS with Twilio using node.js

This blog post is more of a tutorial for myself.  Prior to trying this out, from the online twilio account buy a phone number that allows SMS communication.

The first step is to simple install twilio sdk for node using following command in the directory where you want to send messages from.

mkdir ~/twilio-code
cd ~/twilio-code
npm install twilio

Create a file under the directory twilio-code and name it sendTest.js


var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = '0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';

//require the Twilio module and create a REST client
var client = require('twilio')(accountSid, authToken);

client.messages.create({
to: "+11234567890",
from: "+19876543210",
body: "How you doin?",
}, function(err, message) {
console.log(message.sid);
});

Now running node sendText.js command from the command line, you will be able to send the text message easily.  Each text message sent using twilio is charged some amount so be careful with your testing or use the test SID and AuthToken that Twilio provides.

 

Windows USB/External HDD on OSX

It is such a pain to open any external hard drive or USB stick that has been written and formatted on a windows machine when trying to open it up on a macbook.  I was trying to access photos on my external hard disk that had been originally formatted using a Windows 7 OS (thus NTFS file system) and I could only read the files on my macbook but make no edits to them.  I read online that there are some paid tools that allow you to access the files on such drives but I try not to pay for tools that I’ve never heard of.  The other option is to re-format the drive on mac but that causes wiping out all data on the drive.

I came across the following steps that allow you to enable Mac OSX 10 to access files on such external hard drive without formatting it or losing any data.  Note: You need to have sudo rights (or be the administrator with root privilege) to perform the operation.

Run the following steps on mac OS terminal (can be started by pressing Command + space and typing terminal) :

$> sudo vi /etc/fstab

In the vi editor, add the following line:
LABEL=WESTERNDIGITAL none ntfs rw,auto,nobrowse

and then type :wq! to exit the vi editor window. On the terminal run:

$> diskutil unmount WESTERNDIGITAL
$> diskutil mount WESTERNDIGITAL

Note:  Replace WESTERNDIGITAL with the name of your drive in all lines above with the drive name as showing up in finder window.  If your drive name contains spaces, use quotes around the name e.g. “WD DRIVE”.  You can also find the name by running :

$> ls /Volumes/

There will be a Macintosh HD and the other will be your USB/External HDD. It might happen that the finder window will not show your drive once you have made the change mentioned above.  To open the drive with RW mode, run following in your terminal window:

$> open /Volumes/WESTERNDIGITAL

MongoDB 3.0 Authentication Issue

We upgraded to MongoDB 3.0 version and that caused some of the tools that we used for visualization of Mongo data to stop working.  We use Robomongo at my workplace and it started failing with Authentication error.  The error I saw was as follows:

Failed to authenticate admin@admin with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document

There is a JIRA ticket that is open on the Mongo Issue list which can be found here.  As mentioned in the issue, MONGODB_CR was an older authentication algorithm that was used prior to 3.x versions.  This causes third party tools to stop working when we move to Mongo 3.x because they still try to authenticate using the older mechanism instead of using the newer SCRAM-SHA-1.  I had to perform the following steps to fix the issue and it seems to have worked:

  1. Start MongoDB in non authenticated mode. From the command line, it will be the command
  2. mongod
  3. Switch to the admin database, which stores the usernames and passwords for all users that might need authentication.  If you are using some custom database to store the users, switch to that database
  4. use admin
  5. Now we need to change the authentication schema used for authentication to MONGODB_CR. The value assigned for newer schema is “5” and for the older one is “3”
  6. var schema = db.system.version.findOne({"_id" : "authSchema"})
    schema.currentVersion = 3
    db.system.version.save(schema)

Once the above change is applied, I still was not able to use mongo with authentication. I had to drop and recreate existing users for Robomongo to successfully connect to mongo db in authenticated mode. Once the third party tools also upgrade to work with proper authentication, refer to the link here to again upgrade to using the SCRAM-SHA-1.