【发布时间】:2019-03-31 23:36:35
【问题描述】:
我一直在从事一个涉及从 BigQuery 获取一些数据的 Node 项目。到目前为止一切都很好;我有我的 credential.json 文件(来自 BigQuery)并且项目按预期工作。
但是,我想在项目中实现一项新功能,这将涉及从 BigQuery 获取另一组数据。对于这个新数据集,我有一个完全不同的 credential.json 文件。我的项目似乎只识别我拥有的初始 credential.json 文件(虽然我命名它们不同)。
这是我如何链接我的第一个 credential.json 文件的 sn-p:
function createCredentials(){
try{
const encodedCredentials = process.env.GOOGLE_AUTH_KEY;
if (typeof encodedCredentials === 'string' && encodedCredentials.length > 0) {
const google_auth = atob(encodedCredentials);
if (!fs.existsSync('credentials.json')) {
fs.writeFile("credentials.json", google_auth, function (err, google_auth) {
if (err) console.log(err);
console.log("Successfully Written to File.");
});
}
}
}
catch (error){
logger.warn(`Ensure that the environment variable for GOOGLE_AUTH_KEY is set correctly: full errors is given here: ${error.message}`)
process.kill(process.pid, 'SIGTERM')
}
}
有没有办法将我的两个 credential.json 文件融合在一起?如果没有,如何单独声明使用哪个 credential.json 文件?
【问题讨论】:
标签: javascript node.js google-bigquery credentials