When I call any route in my express server , I am getting this error
TypeError: schema[parameter].validateAsync is not a function
at validate (/home/techrova/Videos/VideoStream/node_modules/express-validation/lib/index.js:18:55)
at /home/techrova/Videos/VideoStream/node_modules/express-validation/lib/index.js:26:25
at Array.map (<anonymous>)
at /home/techrova/Videos/VideoStream/node_modules/express-validation/lib/index.js:26:8
at Layer.handle [as handle_request] (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/layer.js:95:5)
at next (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/layer.js:95:5)
at /home/techrova/Videos/VideoStream/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/index.js:335:12)
at next (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/index.js:275:10)
at Function.handle (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/index.js:174:3)
at router (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/index.js:47:12)
at Layer.handle [as handle_request] (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/index.js:317:13)
at /home/techrova/Videos/VideoStream/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/index.js:335:12)
at next (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/index.js:275:10)
at Function.handle (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/index.js:174:3)
at router (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/index.js:47:12)
at Layer.handle [as handle_request] (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/index.js:317:13)
at /home/techrova/Videos/VideoStream/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/index.js:335:12)
at next (/home/techrova/Videos/VideoStream/node_modules/express/lib/router/index.js:275:10)
at cors (/home/techrova/Videos/VideoStream/node_modules/cors/lib/index.js:188:7)
at /home/techrova/Videos/VideoStream/node_modules/cors/lib/index.js:224:17
at originCallback (/home/techrova/Videos/VideoStream/node_modules/cors/lib/index.js:214:15)
I cannot understand what happening ?
Please explain me ?
Even I can't add details to this question , since I have no clue !!
I cant find out where this error occurs since the error message not showing the exact location and the function validateAsync not found in the code
package.json
{
"name": "videostream",
"version": "2.0.0",
"main": "index.js",
"private": false,
"type": "module",
"engines": {
"node": ">=4.8.0",
"npm": ">=2.15.11",
"yarn": ">=0.20.3"
},
"scripts": {
"start": "npm run dev",
"build": "npm-run-all clean transpile",
"clean": "rimraf dist-server",
"watch:dev": "nodemon",
"server": "node ./dist-server/index.js",
"dev": "NODE_ENV=development npm-run-all build server",
"prod": "NODE_ENV=production npm-run-all build server",
"transpile": "babel . --ignore node_modules,test --out-dir dist-server --copy-files --source-maps --include-dotfiles"
},
"keywords": [
"express",
"node",
"node.js",
"mongodb",
"mongoose",
"es6",
"mocha",
"istanbul",
"REST",
"API",
"boilerplate"
],
"dependencies": {
"async": "3.2.0",
"bcrypt": "5.0.0",
"bluebird": "3.7.2",
"body-parser": "1.19.0",
"compression": "1.7.4",
"cookie-parser": "1.4.5",
"cors": "2.8.5",
"debug": "^4.1.1",
"dotenv": "^8.2.0",
"express": "4.17.1",
"express-busboy": "8.0.0",
"express-jwt": "6.0.0",
"express-validation": "3.0.5",
"express-winston": "4.0.5",
"fcm-push": "1.1.3",
"firebase-admin": "^9.0.0",
"fs": "0.0.1-security",
"helmet": "4.0.0",
"html-pdf": "^2.2.0",
"http-status": "^1.4.2",
"joi": "17.2.0",
"jsonwebtoken": "8.5.1",
"lodash": "4.17.19",
"mailgun-js": "0.22.0",
"method-override": "^3.0.0",
"moment": "2.27.0",
"mongoose": "5.9.27",
"mongoose-delete": "0.5.2",
"mongoose-paginate": "5.0.3",
"mongoose-unique-validator": "^2.0.3",
"morgan": "1.10.0",
"natives": "^1.1.6",
"node-schedule": "^1.3.2",
"nodejs-base64": "^1.0.3",
"nodemailer": "6.4.11",
"nodemailer-mailgun-transport": "2.0.0",
"nodemailer-sendgrid-transport": "^0.2.0",
"nodemailer-sendinblue-transport": "1.2.3",
"otp-generator": "1.1.0",
"request": "^2.88.2",
"rimraf": "^3.0.2",
"socket.io": "^2.3.0",
"stripe": "8.84.0",
"twilio": "^3.48.2",
"winston": "3.3.3"
},
"devDependencies": {
"@babel/cli": "^7.10.5",
"@babel/core": "^7.11.1",
"@babel/preset-env": "^7.11.0",
"babel-plugin-add-module-exports": "1.0.2",
"babel-preset-es2015": "6.24.1",
"babel-preset-stage-2": "6.24.1",
"chai": "^4.2.0",
"commitizen": "^4.1.2",
"coveralls": "^3.1.0",
"cross-env": "7.0.2",
"cz-conventional-changelog": "3.2.0",
"del": "^5.1.0",
"eslint": "7.6.0",
"eslint-config-airbnb-base": "14.2.0",
"eslint-plugin-import": "2.22.0",
"eslint-watch": "7.0.0",
"gulp": "^4.0.2",
"gulp-babel": "8.0.0",
"gulp-load-plugins": "^2.0.3",
"gulp-newer": "^1.4.0",
"gulp-nodemon": "^2.5.0",
"gulp-sourcemaps": "^2.6.5",
"gulp-util": "^3.0.8",
"husky": "^4.2.5",
"istanbul": "1.1.0-alpha.1",
"mocha": "8.1.1",
"npm-run-all": "^4.1.5",
"run-sequence": "^2.2.1",
"supertest": "4.0.2",
"supertest-as-promised": "4.0.2",
"validate-commit-msg": "^2.14.0"
},
"license": "MIT",
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"nodemonConfig": {
"exec": "npm run dev",
"watch": [
"server/*",
"config/*",
"index.js",
".env"
],
"ignore": [
"**/__tests__/**",
"*.test.js",
"*.spec.js"
]
},
"babel": {
"presets": [
"@babel/preset-env"
],
"plugins": [
"add-module-exports"
]
}
}
index.js
import mongoose from 'mongoose';
import util from 'util';
import fs from 'fs';
import config from './config/config';
import app from './config/express';
import socketService from './server/services/socket.service';
import Stripe from './server/services/stripe';
import debuger from 'debug';
const debug = new debuger('videostream:index');
import Promise from 'bluebird';
mongoose.Promise = Promise;
const mongoUri = config.mongo.host;
mongoose.connect(mongoUri, { useNewUrlParser: true,useUnifiedTopology: true, keepAlive: true });
mongoose.connection.on('connected', () => {
console.info('The MongoDB connected successfully');
});
mongoose.connection.on('error', () => {
throw new Error(`unable to connect to database: ${mongoUri}`);
});
if (config.MONGOOSE_DEBUG) {
mongoose.set('debug', (collectionName, method, query, doc) => {
debug(`${collectionName}.${method}`, util.inspect(query, false, 20), doc);
});
}
//
import * as serverer from 'http';
const server = serverer.createServer(app);
//if (!module.parent) {
server.listen(config.port, () => {
console.info(`Your server started on port ${config.port} (${config.env})`);
const charge = { amount: '20', source: 'tok_1EOysZBDFs3Ptf0GdjyTYMN0' };
socketService.startSocket();
});
//}
export default server;
Please help me ?
You need to update your validators on routes. Error comes from express-validation. Please see https://github.com/AndrewKeig/express-validation/issues/122
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With