javascript - 错误:ENOENT:没有这样的文件或目录,打开“../config.json”
问题描述
尝试使用以下代码在 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)
推荐阅读
- excel - 如果列已经包含某个值,则自动递增
- pandas - 将非结构化数据解析为 pandas 数据框
- c++ - 如何为 VS Code 问题匹配器链接目录
- windows - Stunnel 证书被拒绝
- c# - 按天迭代 linq 查询结果以检查条件
- symfony - 使用 Webpack Encore ^0.21.0 时的未知“encore_entry_link_tags”函数
- amazon-web-services - 使用 Auto Scaling 组、CloudFormation 和 CodeDeploy 的蓝/绿部署
- javascript - Summernote - 如何在向图像添加链接时禁用“要显示的文本”
- javascript - 用非线性数据计算方程
- python - TypeError: zip 参数 #2 必须支持迭代 - Python 3