简体   繁体   English

Node.js部署应用程序中的环境变量

[英]Environment variables in nodejs deployed app

I am developing a Node application in which I am connecting to an azure database. 我正在开发一个Node应用程序,在该应用程序中我要连接到一个Azure数据库。 I would like to keep the credentials as environment variables. 我想将凭据保留为环境变量。 I have a .env file and I have the credentials in that. 我有一个.env文件,并且其中有凭据。 When I run the app locally I can fetch the credentials from the file but when it is deployed in Azure, the process.env.SERVER is returning undefined and so I am unable to connect to the server. 当我在本地运行应用程序时,我可以从文件中获取凭据,但是当它在Azure中部署时,process.env.SERVER返回的是未定义的,因此我无法连接到服务器。

In Azure Web Apps, we can define these environment variables in section Application settings -> App settings by using Azure portal : 在Azure Web Apps中,我们可以使用Azure门户在“ 应用程序设置 -> 应用程序设置”部分中定义这些环境变量:

在此处输入图片说明

Then these variables can be accessed from our Node.js code via process.env["variablename"] . 然后可以通过process.env["variablename"]从我们的Node.js代码访问这些变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM