我正在Google Compute Engine上部署基于Ghost的node.js应用程序。 但是,我不确定在config.js写入我的数据库凭证是否是一个好的行为。
config.js文件如下所示:
... 'production': { url: 'http://127.0.0.1:2368', database: { client: 'mysql', connection: { host : '127.0.0.1', user : 'root', password : 'root', database : 'ghost', charset : 'utf8' } }, server: { host: '127.0.0.1', port: '2368' }, },...
但是,这包括在config.js硬编码的数据库凭证。 我不确定这是否足够安全的生产。
我应该使用process.env.xxx环境variables(例如process.env.DB_USER )来设置凭据吗? 在这种情况下,将这些环境variables写入文件并使用configuration运行应用程序的最佳方法是什么?
你不应该把凭据放在任何去源代码库的文件中。
通常所做的是使用您的托pipe平台的控制面板设置的环境variables来获得最简单的解决scheme,或者您可以使用etcd等工具来获得更灵活的解决scheme。 看到:
使用Node,您还可以使用dotenv模块在开发过程中更轻松地设置环境variables。 看到: