express-validator

Express Validator Cannot Show Error Mesages

…衆ロ難τιáo~ 提交于 2020-05-30 08:49:22
问题 Hey guys I want to make an messaging system for my upload webpage. I use express-validator and connect-flash, express-messages app.js const { check, validationResult } = require('express-validator'); . . . app.post('/metin/ekle', [ // username must be an email check('baslik', 'Baslik Gereklidir').notEmpty(), // password must be at least 5 chars long check('konu','Konu gereklidir').notEmpty(), ],function(req, res){ const errors = validationResult(req); if (!errors.isEmpty()) { req.flash(

express server doesn't start after adding checkSchema from express-validator

戏子无情 提交于 2020-04-30 07:04:15
问题 I'm working on an old express server, I was using check from express-validator and it works fine. But I have a post request where the body fields are nested and I need to validate them, so I'm trying to use checkSchema. Apparently its included in the new version, so i upgraded express and express-validator "express": "^4.17.1", "express-validator": "^6.4.0", But when I added checkSchema to my function (code below), the server does not start anymore. When i comment it, it works fine. my import

express server doesn't start after adding checkSchema from express-validator

早过忘川 提交于 2020-04-30 07:03:38
问题 I'm working on an old express server, I was using check from express-validator and it works fine. But I have a post request where the body fields are nested and I need to validate them, so I'm trying to use checkSchema. Apparently its included in the new version, so i upgraded express and express-validator "express": "^4.17.1", "express-validator": "^6.4.0", But when I added checkSchema to my function (code below), the server does not start anymore. When i comment it, it works fine. my import

Express validation, custom async checking

♀尐吖头ヾ 提交于 2020-03-23 02:30:22
问题 So, I have done a pretty good amount of research on this and I am having some issues. router.post('/register', async (req, res) => { const newUser = await usersDb(); // Define the user const email = req.body.email; const username = req.body.username; const password = req.body.password; const confirmPassword = req.body.confirmPassword; // Start user already exist check let userNameCheck = await newUser.findOne({ 'username': username}); req.check('email', 'Email is not valid.').isEmail()

How to implement validation in a separate file using express-validator

亡梦爱人 提交于 2020-03-18 10:07:11
问题 I am trying to use express-validator to validate the req.body before sending a post request to insert data to postgres. I have a route file, controller file and I want to carryout validation in a file called validate.js. Meanwhile, I have installed express-validator and in my server.js I have imported it. Other resources I come across seem to implement the validation in the function that contains the logic for inserting the data. //server.js .... import expressValidator from 'express

Chain functions in JavaScript

南笙酒味 提交于 2020-01-30 06:39:05
问题 Is there a way to chain functions in JavaScript so when last function in chain is called we take into consideration all function in chain that was specified. Basically what I am trying to do is the same thing express-validator does: Something like this: check('password').passwordValidator().optional(); I want to be able to call check('password').passwordValidator(); and check('password').passwordValidator().optional(); 回答1: So you're looking for a sort of builder pattern? You can do that like

New express-validator syntax : validate form processed by multer

北慕城南 提交于 2019-12-13 00:46:09
问题 So, I am building a small app in order to learn how to use express.js. I have a really simple form, submitting one text field and a file simultaneously. This is submitted through FormData, so I'm using multer on the back end to process the request. What I would like to do is perform a validation on the form's text input BEFORE taking any action concerning the file (i.e. save only if the validation succeeds, if not send some kind of error message). I used to do it that way <form id="form"

Validation In Express-Validator

荒凉一梦 提交于 2019-11-30 05:10:21
I am using express-validator for validation. I am using mongoose for database, it also has validation built in. I want to know which one should I use? I also want to know if the validation in express-validator is parallel. Take this code for example: req.checkBody('email', 'Invalid email').notEmpty().isEmail().isUnique(); req.checkBody('password', 'Invalid possword').notEmpty().len(8, 30); req.checkBody('first_name', 'Invalid first_name').notEmpty().isAlpha(); req.checkBody('last_name', 'Invalid last_name').notEmpty().isAlpha(); req.checkBody('dateofbirth', 'Invalid dateofbirth').notEmpty

Validation In Express-Validator

坚强是说给别人听的谎言 提交于 2019-11-29 03:00:05
问题 I am using express-validator for validation. I am using mongoose for database, it also has validation built in. I want to know which one should I use? I also want to know if the validation in express-validator is parallel. Take this code for example: req.checkBody('email', 'Invalid email').notEmpty().isEmail().isUnique(); req.checkBody('password', 'Invalid possword').notEmpty().len(8, 30); req.checkBody('first_name', 'Invalid first_name').notEmpty().isAlpha(); req.checkBody('last_name',

Access request body in check function of express-validator v4

♀尐吖头ヾ 提交于 2019-11-27 03:42:53
问题 I just started using express.js with express-validator to validate some input data and I have problems accessing the request body in the new check API that was introduced in version 4.0.0. In older versions, you simply added express-validator as middleware in your app.js somewhere after body-parser: // ./app.js const bodyParser = require("body-parser"); const expressValidator = require("express-validator"); const index = require("./routes/index"); const app = express(); app.use(bodyParser