Reputation: 93
I'm running a Node.js application in Azure and am trying to get configuration settings like this:
var azure = require('azure');
azure.RoleEnvironment.getConfigurationSettings(function(error, settings) {
if (error) {
console.log(error);
return;
}
console.log('Settings: %s', settings);
});
But the output is always this:
{ "code": "ENOENT", "errno": "ENOENT", "syscall": "connect", "fileName": "\\\\.\\pipe\\WindowsAzureRuntime" }
I'm running Node.Js within IIS using IISNode using all the latest bits. I also get the same error if I run node manually on the Azure VM (i.e. node.exe server.js). Same when running on my PC in the Azure Development Fabric.
Thanks in advance for any help or suggestions!
Upvotes: 3
Views: 1309
Reputation: 379
Here is my solution. It is not good, but at least it works for now.
Create a .NET console application like this
using Microsoft.WindowsAzure; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks;
namespace CloudConfigurationHelper { class Program { static int MaxRetryTime = 10;
public static Dictionary<string, string> GetSettings(string[] keys)
{
Dictionary<string, string> settings = new Dictionary<string, string>();
try
{
foreach (string key in keys)
{
settings[key] = CloudConfigurationManager.GetSetting(key);
}
}
catch
{
MaxRetryTime--;
if (MaxRetryTime <= 0)
{
return settings;
}
Thread.Sleep(2000);
return GetSettings(keys);
}
return settings;
}
static int Main(string[] args)
{
var settings = GetSettings(args);
if (settings.Count != args.Length)
{
return -1;
}
foreach (string key in settings.Keys)
{
Console.WriteLine(key + "=" + settings[key]);
}
return 0;
}
}
}
Put start-up task to read the azure configuration variable and write to .env file. Use https://github.com/motdotla/dotenv to read .env file and load to process.env.
Env.cmd file:
@echo off
cd %~dp0
CloudConfigurationHelper.exe %*
Add start-up task to ServiceDefinition.csdef:
<Task commandLine="Env.cmd YOUR_SETTING_KEY > ..\.env executionContext="elevated" />
process.env["YOUR_SETTING_KEY"]
Upvotes: 0
Reputation: 23764
Since you mentioned you're running in IISNode, it must be a web role. Note the following from the SDK readme:
The Service Runtime allows you to interact with the machine environment where the current role is running. Please note that these commands will only work if your code is running in a worker role inside the Azure emulator or in the cloud.
Upvotes: 2