Javascript 如何向NodeJS Express网站添加验证码?

Javascript 如何向NodeJS Express网站添加验证码?,javascript,node.js,express,recaptcha,Javascript,Node.js,Express,Recaptcha,我有一个带有以下线路的快速路由器: 以及postController.js comment函数,我在其中创建comment对象并从comment.js模型执行create方法: > exports.comment = async function(req, res){ > > var data = { > author: req.body.author, > message: req.body.message

我有一个带有以下线路的快速路由器:

以及postController.js comment函数,我在其中创建comment对象并从comment.js模型执行create方法:

> exports.comment = async function(req, res){
>         
>     var data = {
>         author: req.body.author,
>         message: req.body.message,
>         postId: req.session.postId.id
>     }
>     console.log(data)
> 
>     let comment = new Comments(data)
> 
>     comment.create().then(() => {
>         res.json(data)
>     }).catch(() => {
>         res.json([])
>     }) }
以及Comment.js模型:

> exports.comment = async function(req, res){
>         
>     var data = {
>         author: req.body.author,
>         message: req.body.message,
>         postId: req.session.postId.id
>     }
>     console.log(data)
> 
>     let comment = new Comments(data)
> 
>     comment.create().then(() => {
>         res.json(data)
>     }).catch(() => {
>         res.json([])
>     }) }
const commentscolection=require('../db').db().collection(“Comments”)
const ObjectID=require('mongodb')。ObjectID
const sanitizeHTML=require('sanitize-html')
let Comments=函数(数据){
this.data=数据
这是错误=[]
}
Comments.prototype.cleanUp=函数(){
此参数。数据={
作者:sanitizeHTML(this.data.author),
消息:sanitizeHTML(this.data.message),
createdDate:新日期(),
posted:this.data.posted
}
}
Comments.prototype.validate=函数(){
if(this.data.author==“”){this.errors.push(“您必须提供作者”)}
if(this.data.message==“”){this.errors.push(“您必须提供消息”)}
}
Comments.prototype.create=函数(){
返回新承诺((解决、拒绝)=>{
这个.cleanUp()
这是validate()
如果(!this.errors.length){
commentsCollection.insertOne(this.data)。然后(()=>{
解决()
}).catch(()=>{
这个.errors.push(“db问题”)
拒绝(此。错误)
})
}否则{
拒绝(此。错误)
}
})
}
Comments.viewCommentsByID=函数(id){
返回新承诺(异步(解析、拒绝)=>{
let comment=wait comments集合.find({postId:id}).sort({createdDate:-1}).toArray({},函数(err,p){
})
解决(评论)
})
}
module.exports=注释