I have the following code which works fine locally, but when I deploy to an Azure function it fails to read in the contents of the .env file at runtime, when debugging each of the config items is "undefined". .Env file is deployed to Azure with correct entries and the function executes correctly when I hard code the config variables to test. I assume I need to do something differently to get this to work on Azure?
const sql = require('mssql')
require('dotenv').config();
const dbConfig = {
server: process.env.databaseServer,
database: process.env.databaseName,
user: process.env.databaseUser,
password: process.env.databasePassword,
port: 1433,
options: {
encrypt: true,
"enableArithAbort": true
}
};
Azure function is a packed service, its process.env has reloaded properties of the Azure function environment, by default, it will not load your .env file.
It is recommended that defining all your .env content in Azure function application settings:

Simple demo to get this value:

Related doc sees here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With