ARCHIVE NOTICE

My website can still be found at industrialcuriosity.com, but I have not been posting on this blog as I've been primarily focused on therightstuff.medium.com - please head over there and take a look!

Friday 12 May 2017

connecting node.js to the azure table storage emulator

Once again, solid software is rendered useless by a lack of documentation. I've just wasted way too much time connecting my node app to an emulated table, so I'm going to spell it out for you so that you don't have to do the same.
  1. The npm azure-storage package instructions are found here, the emulator software is found here and the storage explorer is found here.
  2. Once the emulator has been installed, you'll need to start it. The init operation worked fine for me (I'm running SQL Server 2012 Express anyway), but the start operation failed and it took a while to realize that ports 10000 - 10002 (or is that 3?) need to be available; the software blocking could be anywhere from backup software or bittorrent to malware.
    Good to know.
    There doesn't appear to be any way to customize the ports used.
  3. To verify that your emulator is running correctly, connect using the storage explorer.
    1. Select "Use a storage account name and key"
    2. Set the account name and authentication key (see point 6 below)
    3. Set the storage endpoints domain to "Other" with a value of 127.0.0.1
    4. Select "Use HTTP"
  4. The emulator runs on http NOT https, which shouldn't affect you once you've got your connection configured correctly. For some people the authentication requires setting your system time to UTC / GMT, for others it's setting the environment variable NODE_TLS_REJECT_UNAUTHORIZED to 0; the latter can be done in node.js with
    process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
    
    
  5. There are two ways to instantiate a table service object. Assuming
    var azure = require('azure-storage');
    1. var tableSvc = azure.createTableService(account, key, '127.0.0.1:10002');
      or
    2. process.env.AZURE_STORAGE_ACCOUNT = account;
      
      process.env.AZURE_STORAGE_ACCESS_KEY = key;
      
      process.env.AZURE_STORAGE_CONNECTION_STRING = connectionString;
      
      var tableSvc = azure.createTableService();
  6. The account name, authentication key and connection string are public, invariable and for emulation purposes only:
    Account name: devstoreaccount1

    Authentication Key:
    Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==

    Connection String: UseDevelopmentStorage=true