简体   繁体   English

Express JS-使用服务器端JS检查应用程序是否在本地主机上运行

[英]Express JS - Using server side JS check if app is running on localhost

I am needing to check if my node js app using ExpressJS is running on my localhost (Development env.) and not on the live server and execute certain code if so. 我需要检查使用ExpressJS的Node js应用程序是否正在本地主机(开发环境)上运行,而不是在实时服务器上运行,如果有,请执行某些代码。 This has to be done server side. 这必须在服务器端完成。 Any ideas how to check this? 有什么想法如何检查吗?

Pass process.env variable to your node.js instance like this (for example) 像这样将process.env变量传递给您的node.js实例(例如)

node -e 'process.env.NODE_ENV = "development"'

and then just use 然后就用

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

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

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