【问题标题】:Error: ENOENT: no such file or directory, open '../config.json'错误:ENOENT:没有这样的文件或目录,打开“../config.json”
【发布时间】:2019-01-26 01:03:13
【问题描述】:

尝试使用以下代码在 nodejs 中为 AWS SES 加载外部配置文件。

aws.config.loadFromPath('../config.json');

它会抛出这个错误

Error: ENOENT: no such file or directory, open '../config.json'

现在文件在那个位置,但上面的代码看不到它。

请问有什么快速的解决方法吗?

更新

它发生在本地和服务器上。

【问题讨论】:

  • 试试./../config.json
  • 该路径也有同样的错误。刚刚试了一下。
  • 可能是这个process.cwd()+'./../config.json'
  • 返回这个/node_modules/aws-sdk/lib/request.js:31 throw err; ^ InvalidParameterValue: Missing final '@domain'
  • 使用 SSM(Systems Manager) 参数存储来保存您的配置值并通过它进行访问。

标签: javascript node.js amazon-web-services amazon-ses


【解决方案1】:

使用__dirname

let AWS = require('aws-sdk')
const path = require('path')
const dirPath = path.join(__dirname, '/config.json')

AWS.config.loadFromPath(dirPath)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    • 2021-06-08
    • 2019-06-24
    • 2016-07-05
    • 2013-02-04
    • 2020-09-14
    • 2019-08-31
    相关资源
    最近更新 更多