I am trying to validate user input with express-validator I am following this tutorial here: https://heynode.com/tutorial/how-validate-and-sanitize-expressjs-form/
However i'm receiving the error "TypeError: check is not a function" even though i have imported it at the top. Here is my code:
const express = require('express');
const web3 = new Web3(new Web3.providers.HttpProvider(serverUrl));
const rateLimit = require("express-rate-limit");
const { check, validationResult } = require('express-validator');
const authenticateJWT = async (req, res, next) => {
const authHeader = req.headers.authorization;
if (authHeader) {
code omitted
} else {
res.sendStatus(401);
}
};
var loginValidate = [
check('username', 'Username Must Be an Email Address').isEmail(),
check('password').isLength({ min: 8 })
.withMessage('Password Must Be at Least 8 Characters')
.matches('[0-9]').withMessage('Password Must Contain a Number')
.matches('[A-Z]').withMessage('Password Must Contain an Uppercase Letter')];
router.post('/order/buy_order', authenticateJWT , loginValidate, async (req, res) => {
try {
code omitted }
} catch (error) {
console.log(error, "makeBuyOrder error in routes");
res.send(null).end();
}
});
How can i fix this?