476
questions
0
votes
0
answers
21
views
How can I mock up the express-validator withDefaults function using jest?
I am trying to unit test my validation segment which uses express-validator.
This is the start of the segment:
const errorMsgs = require('../lib/error-messages');
const validationResults = ...
-2
votes
0
answers
29
views
I am trying to sanitize object but still getting error snyk.io in | NODE.js [closed]
I have 2 types of error in snyk report https://snyk.io/ I don't know if it can be solved with Deepcode AI as well but appreciate the answers.
SQL injection: unsanitize input from an HTTP parameter ...
0
votes
0
answers
15
views
express-validator Integer or null
I need to do simple validation and allow only Integer values or null. I'm using express-validator 7.2.0 and I'm having a hard time implementing it...
here is my validation middleware:
check('contactID'...
1
vote
1
answer
41
views
How to ignore single quotes in the validator.js isAlphanumeric function
I am trying to validate a string using express validator, specifically with the function isAlphanumeric, but I would like to add space, dash, and single quote as characters to accept.
Here is my code:
...
0
votes
0
answers
22
views
Express validation - delegate code in separate file
How can I call the endpoint defined in another file from this router ?
this im my router.js file:
const express = require('express');
const { body, validationResult } = require('express-validator');
...
1
vote
0
answers
21
views
Why oject property express-validator changed
Property Object change when I used in Array
I had object property types validationChain Object Validator. And I have two array use this obj Two array. I want to know that, why property of this obj had ...
0
votes
2
answers
21
views
Validation Rules for Non-Empty Strings with express-validator Not Working as Expected
ValidationChain Express-validator not working when use obj config
Anyone can help me for this problem. I have two this property. "Status" not working when my req.body.status="", ...
0
votes
4
answers
55
views
Not capable of checking a falsy value at the validation middleware
I've found a weird behavior when trying to check for a falsy value. I guess it is related to the parser across the HTTP. All values inserted (eg http://www.localhost:3000/knex/0) are converted into ...
1
vote
2
answers
89
views
express-validator rejects valid input
I have tried a lot to find the problem, but nothing worked. Here the details, including my errors (at the end). I am just putting the relevant code here. I use express-validator 7.1.0
I am trying to ...
0
votes
1
answer
33
views
Ensuring integer or array of integers with express-validator
I'm puzzled with a validator while trying express.
An optional parameter I receive to my route, flags, should either be an integer or an array of integers.
The array of integers part is checked with ...
0
votes
1
answer
144
views
Express-Validator: how to stop validation after checking for mandatory parameters?
I am using Express-Validator to validate some query parameters to a RESTful API written in node.js. I would like to "bail()" after running the mandatory checks so that there will be a ...
0
votes
1
answer
54
views
Node express.js - express-validator: validationResult not working on middleware
I using express-validator plugin for validate my express.js project.
When i check validation in controller with validationResult method, everything is ok and validationResult return errors and ...
-1
votes
3
answers
38
views
What are the mistakes have done in the router localhost:4000/rooms/book/1?
const express = require("express");
const { body, validationResult } = require("express-validator");
const app = express();
const PORT = 4000;
app.use(express.json());
const ...
-1
votes
1
answer
69
views
what is the difference between notEmpty and exists in express-validator
I can't understand what is the difference between exists and notEmpty in express-validator both works the same.
0
votes
0
answers
70
views
Validation chain not working in express-validator
const express = require("express");
const router = express.Router();
const User = require("../Models/User");
const { body, validationResult } = require("express-validator"...
0
votes
1
answer
71
views
Validation from express-validator not working for a middleware
I am trying to create a restaurant at backend where every thing seems right, but when i pass validation middleware at create restaurant route it gets fired even though i filled every fields as they ...
0
votes
0
answers
51
views
TypeError: Cannot set properties of undefined (setting 'message') in Express Validator
Getting this error:
\node_modules\express-validator\src\chain\validators-impl.js:25
this.lastValidator.message = message;
^
TypeError: Cannot set properties of undefined (setting 'message')
TypeError: ...
0
votes
0
answers
43
views
express-validator not validating when seperated into several files
I've got route file
import express, { Request, Response } from "express";
import * as authController from "../controllers/authController";
import {
validateUserRegistration,
} ...
0
votes
1
answer
54
views
Use input sanitization on passport callback routes?
Should we use input sanitation to escape special characters on passport js callback routes?
I'm specifically utilizing the magic-link and microsoft strategies, but this question would apply to any ...
0
votes
1
answer
118
views
Express Validator .isLength and isEmail is not working
router.post("/", (req, res) => {
body("name").isLength({ min: 3 }); // Validate name length
body("email").isEmail(); // Validate email format
body("password&...
0
votes
1
answer
70
views
How to check if the DOB is smaller than DOD in nodejs express validator
I am using the express validator for the validation in nodejs. I need to show error message if the user select date of birth greater than date of dead.
check('dob').notEmpty().bail().withMessage('...
1
vote
2
answers
44
views
Express-validator returns error on sending request through ReactJs app but not in postman/thunderclient
I created an context in React app which uses fetch api to connect to my server on localhost. I submit the form using handleClick function which calls the addNote function of the context. The addNote ...
0
votes
0
answers
216
views
express-validator issues with checkSchema
I'm new to express in general but I feel like my issue is unrelated. Attached below is my route with the checkSchema call to validate different fields. The intended functionality is to only validate ...
0
votes
0
answers
136
views
Custom server bodyParser and nextauth conflicting
I have my ...nextauth as guided in documentation like so:
I have a custom server as so:
app.prepare().then(() => {
const server = express();
server.use(cors())
server.use('/...
0
votes
1
answer
319
views
Allowing empty strings in Validator.js
I am trying to combine Zod and Validator.js to validate form data. I want to allow empty strings "" for optional fields. I think this snippet should work but it does NOT and I cannot figure ...
0
votes
2
answers
106
views
Express validator always returning error even when valid
I am using postman to send a post request with some data in the body, but express validator is always returning the error array. Here is the index.js code:
import express from "express";
...
0
votes
0
answers
30
views
Express Validator unexpected token error on EC2 instance but works fine on local machine
terminal errors
I'm trying to host an API on an EC2 instance for a class project. On my local machine (Mac mini, 13.4.1, M2 chip) I enter the repository, run npm start, everything works. Through SSH I'...
0
votes
2
answers
130
views
Express-validator checking field in cookies instead of body
I have the following validator:
const validationSchema = checkSchema({
'applicant.name': {
exists: true,
errorMessage: 'Name field is required',
},
});
and the beginning of ...
0
votes
0
answers
57
views
how to fix this.validator is not a function
validationResult is not working well and returns typeError validatorResult is not a function but the problem still continues
ValidatorFields.js file:
const { validationResult } = require("express-...
0
votes
1
answer
318
views
Express-validator 7.0.1 isDate() always return false
The following code works for express-validator 6.14.2.
const checkDate = check("date").isDate();
// simplified but you get the idea,
app.post(
"/path1",
[checkDate],
...
0
votes
0
answers
126
views
I want to use schema-validation technique (checkSchema) of express validator for validating the body of the request and return any errors
router.post(
"/",
[
body("name").isLength({ min: 3 }),
body("email").isEmail(),
body("password").isLength({ min: 5 }),
],
(req, res) => {
...
-1
votes
1
answer
92
views
Why does express-validator not detect missing fields when validating XML input?
I have an express-based server that parses xml rather than json (using body-parser-xml).
I then use express-validator to validate the body input like this (the real code doesn't look quite like this, ...
0
votes
0
answers
34
views
Validation a request as function without middleware
is there a use of express-validator as non-middleware, just a function to send request json and take errors as a return.
import express from 'express';
import { body, validationResult } from 'express-...
-1
votes
1
answer
507
views
Is there any way to check the JSON string with express-validator?
The express-validator attempts to examine the "email" field inside the "userData" object as follows.
userRouter.post('/', [
header('type').isIn(...),
body('userData')....
0
votes
1
answer
63
views
Express-validator middleware either times out, is not able to read req.params, or complains about being a promise instead of a call back function
I am using express-validator for an Express backend application. I have used the validator in some routes already, but in this case, I am trying to make a DB call and based on a value returning a ...
0
votes
0
answers
51
views
Express Validator: field mandatory if another field has a value, but rejected otherwise?
I'm trying to write a validation chain with the following reqs:
Field type is mandatory and one of a set of values
Field negativeName is mandatory if type === 'binary' but otherwise should be ...
-1
votes
1
answer
50
views
Ajax 400 error after Express Validator runs server-side validation
I am trying to fix a form handler that always throws a 400 error after middleware validation.
The middleware validation goes like this:
const contactValidate = [
check('name')
.exists()
....
0
votes
0
answers
30
views
Node js using express-validation
I have this file validation:
import { check } from "express-validator";
exports.validateAuthor = [
check('name', 'name is required').not().isEmpty()
]
and I used it on:
import { Router ...
0
votes
0
answers
286
views
Using express-validator to validate array object value from req.body
I am trying to send an array of the object as a form-data using postman. Then validate the data using express-validate I created a function that will handle the validation process of my body.
validate....
0
votes
1
answer
51
views
How can I make ExpressValidator validate empty array OR contents of array
I have an array that passes through my validator, which currently looks like this:
expressValidator.body('animals.*').custom(checkAnimal).withMessage('Must provide an array containing valid animals')
...
1
vote
2
answers
58
views
Validating resource existence before performing updates or deletes in Expressjs
I'm developing a web application using Express.js and MongoDB, and I'm implementing validation with express-validator for updating or deleting resources. However, I have a concern about the ...
0
votes
1
answer
192
views
express-validator: isEmail() won't report if body.email doesn't exist
Updated:
express-validator 7.0.1, node 16.16.0
follow the 1st example at https://express-validator.github.io/docs/guides/validation-chain
my initial code is like this
app.post('/newsletter',
body(&...
0
votes
1
answer
398
views
Creating a custom validator function in Typescript for expressValidator class - parameter implicitly has 'any' type
I want to create a custom validation function for express-validator in typescript by extending the 'body' object.
Looking at the support page I copied and pasted
import { ExpressValidator } from '...
2
votes
1
answer
1k
views
Property 'path' does not exist on type 'ValidationError'. with express-validator 7.0.1
I am trying to access the path field from express-validator 7.0.1. But when I do, I receive an error "Property 'path' does not exist on type 'ValidationError'".:
import express, { Request, ...
2
votes
2
answers
436
views
Use isStrongPassword in validation schema
I'm trying to define a schema using express-validator in which I set the "isStrongPassword" option. The "usernameSchema" works fine, but the "passwordSchema" doesn't pass ...
-1
votes
1
answer
2k
views
Jest.spyOn return an error -"Cannot use spyOn on a primitive value; undefined given" Express.js package "express-validator"
I use Express.js, to validate requests, I use a package express-validator. And I want to test the controller:
import { validationResult } from "express-validator";
class ...
0
votes
0
answers
228
views
jest mock express-validator validationResult
Is it possible to mock validationResult, just to prove it was called and that the controller acts accordingly when the validation fails?
postSetup: async function (req: Request, res: Response): ...
0
votes
0
answers
36
views
express-validation sequential processing [duplicate]
I am following this guide running-imperatively and trying to implement the sequential processing sample.
const validate = validations => {
return async (req, res, next) => {
for (let ...
0
votes
2
answers
730
views
Express Validator to validate time
I want to validate Time like this 18:14 with express-validator. When i used isTime as stated in validator like this body("StartTime").isTime().withMessage("Value must be time with HH:MM ...
1
vote
0
answers
81
views
express-validator - validate images array
I'm working on a project using Multer to upload an array of images in a field named "images". I need to validate that all images are either PNG or JPG, but I'm having trouble getting the ...