Javascript NODE.JS错误:无法在视图目录中查找视图“/articles/[object object]”

Javascript NODE.JS错误:无法在视图目录中查找视图“/articles/[object object]”,javascript,node.js,mongodb,express,Javascript,Node.js,Mongodb,Express,大家好,我目前正在为我的网站创建一个评论系统。然而,我在标题中得到了一个错误。 我的表格 邮递 text区域=document.querySelectorpost; textarea.addEventListener'input',autoResize,false; 函数自动调整大小{ this.style.height='auto'; this.style.height=this.scrollHeight+'px'; } 这是处理表单的代码 const express=需要“express”

大家好,我目前正在为我的网站创建一个评论系统。然而,我在标题中得到了一个错误。 我的表格

邮递 text区域=document.querySelectorpost; textarea.addEventListener'input',autoResize,false; 函数自动调整大小{ this.style.height='auto'; this.style.height=this.scrollHeight+'px'; } 这是处理表单的代码

const express=需要“express” const router=express.router 常量路径=需要“路径” const Article=需要“/../models/Article” const Comment=require'/../models/Comment' const User=require./../models/User' router.post'/',异步请求,res,next=>{ console.logreq.body.post req.comment=新注释 let comment=req.comment let user=wait user.findOnereq.body.user\u id let article=等待article.findOnereq.body.article\u id comment.content=req.body.content comment.userName=req.user.name user.comments.pushcomment.\u id article.comments.pushcomment.\u id 试一试{ article=等待article.save comment=wait comment.save res.redirect`/articles/${article.slug}` }抓住e{ res.render`/articles/${path}`,{article:article} } } module.exports=路由器 我已确定节点未正确传输req.body.content,因为在我尝试处理请求时,它显示为未定义。我怎样才能解决这个问题


谢谢

在res.render/articles/${path}这一行中,当您在文件顶部执行const path=require'path'时,path是一个对象。要填充req.body,您需要使用中间件来解析传入的请求。如果使用json格式,它是app.useexpress.jsonHiĐăng,我可以从表单中抓取一些项目,但文本区域似乎没有通过。我试过你建议的行动,但没有成功。