nodejs+koa post请求写入数据到文件吧报错?
// 存储资源到本地
async save_upload_asset(ctx) {
const list = []
//获取post传递的数据
const { key, url } = ctx.request.body
// 保存数据到data目录中
ctx.body = await new Promise(res => {
list.push({ key, url })
fs.writeFile(require('../data/upload_asset.txt'), JSON.stringify(list), (err) => {
console.log(res)
res({
code: 0,
data: err ? false : true,
success: true
})
})
})
}
在fs.witeFile 的err 中报如下错误, 请问是什么原因啊
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of Object
回复
1个回答

test
2024-06-29
已解决, writeFile 第一个参数必须是字符串路径
回复

适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容