验证我的node.js实例是dev还是生产 [英] Verify if my node.js instance is dev or production

查看:175
本文介绍了验证我的node.js实例是dev还是生产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,每当我要将node.js服务器部署到我的生产服务器时,我需要将我的各种连接的所有IP / DNS /用户名/密码更改为我的数据库和外部API。

Right now, whenever I want to deploy a node.js server to my production server, I need to change all the IP/DNS/username/password for my various connection to my databases and external APIs.

这个过程很烦人,有没有办法验证当前正在运行的node.js实例是在cloud9ide还是实际上是我的生产快乐的smartmachine?

This process is annoying, is there a way to verify if the currently running node.js instance is in cloud9ide or actually my production joyent smartmachine?

如果我能够在运行的代码中确定我的node.js实例运行在哪个服务器上,我将添加一个条件,将值设置为产品或开发商

If I am able to detemrine (in my running code) on which server my node.js instance is running , I'll add a condition that set the values to the prod or dev.

谢谢

推荐答案

通常你应该运行一个节点应用这样的生产:

Normally you should run a node app in production like this:

NODE_ENV =生产节点app.js

应用程序与Express,Socket.IO等使用 process.env.NODE_ENV 来计算环境。

Applications with Express, Socket.IO and other use process.env.NODE_ENV to figure out the environment.

在开发过程中,您可以省略,只需运行 node app.js

In development you can omit that and just run the app normally with node app.js.

可以在您的代码中检测环境:

You can detect the environment in your code like this:

var env = process.env.NODE_ENV || 'dev';
loadConfigFile(env + '.json', doStuff);

资源:

如何在express.js应用程序中检测环境?

这篇关于验证我的node.js实例是dev还是生产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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