我意识到这可能是一个愚蠢的问题,所以感谢您花时间阅读(并希望能回答)它。我对 Javascript 和节点都是新手,所以请假设我知道一些行话。
我正在尝试使用谷歌客户端库中的 table.delete() 函数(链接如下)删除 node.js(v12.15.0)中的 Big Query 表。
https://googleapis.dev/nodejs/bigquery/latest/Table.html#delete
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
async function deleteTable(
datasetId = 'my_dataset',
tableId = 'my_table',
) {
console.log(`Deleting table ${tableId}`);
try {
const [table] = await bigquery
.dataset(datasetId)
.table(tableId)
.delete();
console.log(`Table ${tableId} deleted.`);
} catch (err){
console.log(err);
}
}
deleteTable();
要运行此程序,谷歌需要从您的 Big Query 帐户进行身份验证,我已将其作为 json 文件下载并存储在“凭据”文件夹中。该路径作为环境变量保存在我的 ~/.bash_profile 中:
export GOOGLE_APPLICATION_CREDENTIALS="/Users/tom/Desktop/work/test/credentials/google_application_credentials.json"
当我尝试运行上述脚本时,出现 ENOENT 错误:
Error: The file at {[contents of google_application_credentials.json]} does not exist, or it is not a file.
ENOENT: no such file or directory, lstat '/Users/tom/Desktop/work/test/{[contents of google_application_credentials.json]}
at Object.realpathSync (fs.js:1529:7)
at GoogleAuth._getApplicationCredentialsFromFilePath (/Users/tom/Desktop/work/test/node_modules/google-auth-library/build/src/auth/googleauth.js:250:27)
at GoogleAuth._tryGetApplicationCredentialsFromEnvironmentVariable (/Users/tom/Desktop/work/test/node_modules/google-auth-library/build/src/auth/googleauth.js:192:25)
at GoogleAuth.getApplicationDefaultAsync (/Users/tom/Desktop/work/test/node_modules/google-auth-library/build/src/auth/googleauth.js:130:33)
at GoogleAuth.getClient (/Users/tom/Desktop/work/test/node_modules/google-auth-library/build/src/auth/googleauth.js:502:28)
at GoogleAuth.authorizeRequest (/Users/tom/Desktop/work/test/node_modules/google-auth-library/build/src/auth/googleauth.js:543:35)
at BigQuery.makeAuthenticatedRequest (/Users/tom/Desktop/work/test/node_modules/@google-cloud/common/build/src/util.js:374:28)
at BigQuery.request_ (/Users/tom/Desktop/work/test/node_modules/@google-cloud/common/build/src/service.js:129:18)
at BigQuery.request (/Users/tom/Desktop/work/test/node_modules/@google-cloud/common/build/src/service.js:140:36)
at Dataset.request_ (/Users/tom/Desktop/work/test/node_modules/@google-cloud/common/build/src/service-object.js:231:21) {
errno: -2,
syscall: 'lstat',
code: 'ENOENT',
path: '/Users/tom/Desktop/work/test/{[contents of google_application_credentials.json]}
显然,这个脚本在 /Users/tom/Desktop/work/test 中搜索 .json 文件的内容,而不是文件本身,但我不知道为什么。bash配置文件中的路径肯定是正确的,环境变量也正确更新了。如果有人能帮我一把,我将不胜感激!如果您需要更多信息,请告诉我。