2

Here is my php config file I use (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/';   
}

?>

I would like to use this DBConfig inside my nodejs (I use npm mysql package).

What is the best way/strategy to have 1 single config file for both PHP and NODEJS ?

Regards

yarek
  • 11,278
  • 30
  • 120
  • 219

1 Answers1

0

According to the 12 factor app use environment variables. Sensitive credentials should not be checked into your version control repo.

If you cannot use environment variables, I would advise using something like a file outside of version control like /config/database.json

You can easily parse .json in Node as defined here or PHP defined here.

Community
  • 1
  • 1
Steve
  • 1,423
  • 10
  • 13