Node.js – How to Specify Azure Storage Connection String

azurenode.jsstorage

I'm trying to use azure storage for storing the assets in node js application. I followed the official documentation. But the connection string specification is not working. So i'm getting error.

throw new SyntaxError(SR.INVALID_CONNECTION_STRING); ^

SyntaxError: Connection strings must be of the form "key1=value1;key2=value2".

at Object.exports.parseAndValidateKeys (/home/sakthips/Downloads/Projects/node/storage-blobs-node-quickstart/node_modules/azure-storage/lib/common/services/servicesettings.js:83:15)

In the .env file, i specified like this

AZURE_STORAGE_CONNECTION_STRING='DefaultEndpointsProtocol=****..'

but it's not working. Can anyone explain why it's not working

Best Answer

The .env must be read before azure store gets initialized. Use

require('dotenv').load();

And do not call

const storage = require('azure-storage')

until just before it is actually used.

Related Topic