尝试使用以下代码在 nodejs 中为 AWS SES 加载外部配置文件。
aws.config.loadFromPath('../config.json');
它抛出这个错误
Error: ENOENT: no such file or directory, open '../config.json'
现在该文件在该位置,但上面的代码没有看到它。
请问有什么快速的解决方法吗?
更新
它发生在本地和服务器上。
最佳答案
使用__dirname
let AWS = require('aws-sdk')
const path = require('path')
const dirPath = path.join(__dirname, '/config.json')
AWS.config.loadFromPath(dirPath)
关于javascript - 错误 : ENOENT: no such file or directory, 打开 '../config.json',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51921605/