【问题标题】:How nodejs and php can share the same config file to access database?nodejs 和 php 如何共享同一个配置文件来访问数据库?
【发布时间】:2015-12-13 03:30:17
【问题描述】:

这是我使用的 php 配置文件 (config.php)

<?php 

class DbConfig{   
    const NAME = 'myDB';
    const USER = 'myUser';
    const PASS = 'myPass';
    const HOST = 'localhost';
}

class Servers {
    const NODE = 'http://127.0.0.1';
    const RTMP = 'http://127.0.0.1:1935/';   
}

?>

我想在我的 nodejs 中使用这个 DBConfig(我使用 npm mysql 包)。

为 PHP 和 NODEJS 提供 1 个单一配置文件的最佳方式/策略是什么?

问候

【问题讨论】:

  • json、csv 或 xml 都很容易解析。到目前为止,您尝试了什么?
  • 我什么都没试过。我现在有 2 个配置文件让我感到不安。

标签: php node.js


【解决方案1】:

根据12 factor app使用环境变量。 不应将敏感凭据签入您的版本控制存储库。

如果您不能使用环境变量,我建议您使用版本控制之外的文件,例如 /config/database.json

您可以轻松解析Node as defined herePHP defined here 中的.json。

【讨论】:

    猜你喜欢
    • 2019-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多