4

The App Settings for an Azure Function App contain values for database connection strings that can be set in the portal. In C# they can be accessed using

ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString

For an Azure Function written in JavaScript, is there an equivalent construction that has access to the connection strings? I understand that they can be stored in the application settings, but since there is a section on the portal devoted to connection strings, I am asking if this has any application to Node.js functions.

1

3 Answers 3

8

The distinction between app settings and connection strings makes sense in .NET, but not as much in Node. When using Node, the suggestion is to use app settings for all your secrets and connection strings. You can them access them using process.env.YourAppSetting.

And to answer your question directly, there is no easy way to access connection strings in Node, unless you start making assumptions on prefixes that are not guaranteed to work forever.

Sign up to request clarification or add additional context in comments.

Comments

5

try

process.env['YOUR_APP_SETTING'];

Microsoft Documentation

4 Comments

Thanks, this works for the Application Settings for the Function App, but there is another section in the Azure portal called Connection Strings, I am asking how we can retrieve these values.
Oh yea, I see what you mean. Hmm.
It's not elegant but, I suppose you could duplicate the connection string as an app setting. Microsoft does not appear to give a way to access the connection string directly that I can find.
So this means I have to save my connection string as an appsetting?
4

I ran into same issue and I was under the same impression that we cannot access connection strings in NodeJs application through Runtime Environment variable.

But after thorough checking in the Microsoft documentation, got to know that we can access the connection strings in Node JS, PHP, etc., which are of custom type as below

CUSTOMCONNSTR_<connection_string>

Ref: https://learn.microsoft.com/en-us/azure/app-service/web-sites-configure#connection-strings

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.