如何使用Firebase Cloud Functions检测环境是开发环境还是生产环境? [英] How to detect if environment is development or production with Firebase Cloud Functions?

查看:63
本文介绍了如何使用Firebase Cloud Functions检测环境是开发环境还是生产环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Firebase Cloud Functions检测我的服务器环境是开发环境还是生产环境?

我需要这样的东西:

  if(process.env.NODE_ENV ==='开发'){//针对开发环境做特定的工作}否则if(process.env.NODE_ENV ==='生产'){//针对生产环境做特定的工作} 

解决方案

process.env.FUNCTIONS_EMULATOR

process.env 的firebase函数项目上,有一个名为 FUNCTIONS_EMULATOR 的布尔变量,它指示该进程是在模拟器上还是在服务器上运行./p>

这足以确定环境是开发环境还是生产环境.

  process.env.FUNCTIONS_EMULATOR === true 

obs:在某些环境中,变量可能是字符串'true'而不是布尔值 true

How can I detect if my server environment is development or production with Firebase Cloud Functions?

I need something like this:

if(process.env.NODE_ENV === 'development'){

   //DO STUFF SPECIFIC TO DEV ENVIRONMENT

}
else if(process.env.NODE_ENV === 'production'){

   //DO STUFF SPECIFIC TO PRODUCTION ENVIRONMENT

}

解决方案

process.env.FUNCTIONS_EMULATOR

At process.env, on firebase functions projects, there is a boolean variable called FUNCTIONS_EMULATOR, which indicates if the process is running on an emulator or on server.

this is enough to determine if environment is dev or production.

process.env.FUNCTIONS_EMULATOR === true

Obs: In some environments the variable might be a String 'true' instead of Boolean true

这篇关于如何使用Firebase Cloud Functions检测环境是开发环境还是生产环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆