首页 > 解决方案 > 错误:ENOENT:没有这样的文件或目录,打开“../config.json”

问题描述

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

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

它抛出这个错误

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

现在该文件在该位置,但上面的代码没有看到它。

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

更新

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

标签: javascriptnode.jsamazon-web-servicesamazon-ses

解决方案


利用__dirname

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

AWS.config.loadFromPath(dirPath)

推荐阅读