javascript Express + node.js 中的服务器端数据验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12736458/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Server side data validation in Express + node.js
提问by mark
My server is comprised of three major components - node.js + express + mongojs. Right now I am looking for a way to plug in server side validation of the client input. Mongoose offers it through its Schema definitions, however, I would like the validation to be independent of the particular DB layer.
我的服务器由三个主要组件组成 - node.js + express + mongojs。现在我正在寻找一种方法来插入客户端输入的服务器端验证。Mongoose 通过其 Schema 定义提供它,但是,我希望验证独立于特定的 DB 层。
Ideally, I am looking for something supporting declarative validation rules (again, like the mongoose schemas), but without any coupling with mongo.
理想情况下,我正在寻找支持声明性验证规则的东西(再次,像猫鼬模式),但没有与 mongo 的任何耦合。
Any ideas?
有任何想法吗?
P.S.
聚苯乙烯
I am mentioning Express, because my intention is to plug the validation layer as an Express middleware. This should work, shouldn't it?
我提到 Express,因为我的目的是将验证层作为 Express 中间件插入。这应该有效,不是吗?
P.P.S.
缴费灵
An extra bonus, if the same javascript code can be utilized on the client side as well.
如果在客户端也可以使用相同的 javascript 代码,那就是额外的好处。
采纳答案by PherricOxide
I've had good luck with node-validator: https://github.com/chriso/node-validator
我在 node-validator 上很幸运:https: //github.com/chriso/node-validator