mschwarzmueller / nodejs-basics-tutorial

The source code for my node.js tutorial series
MIT License
404 stars 420 forks source link

I found an error like expressValidator is not a function #7

Open ghost opened 4 years ago

ghost commented 4 years ago

Here, It's my error... . . .

npm start

expressfirstapp@0.0.0 start C:\Users\JEET\Desktop\NodeJs\nodeProjects\ValidationSession node ./bin/www

C:\Users\JEET\Desktop\NodeJs\nodeProjects\ValidationSession\app.js:24 app.use(expressValidator());

^

TypeError: expressValidator is not a function at Object. (C:\Users\JEET\Desktop\NodeJs\nodeProjects\ValidationSession\app.js:24:9) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:643:32) at Function.Module._load (internal/modules/cjs/loader.js:556:12) at Module.require (internal/modules/cjs/loader.js:683:19) at require (internal/modules/cjs/helpers.js:16:16) at Object. (C:\Users\JEET\Desktop\NodeJs\nodeProjects\ValidationSession\bin\www:7:11) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! expressfirstapp@0.0.0 start: node ./bin/www npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the expressfirstapp@0.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

ghost commented 4 years ago

Here, It's my code. . . . var express = require('express'); var path = require('path'); var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var hbs = require('express-handlebars'); var expressValidator = require('express-validator'); var expressSession = require('express-session');

var routes = require('./routes/index');

var app = express();

// view engine setup app.engine('hbs', hbs({extname: 'hbs', defaultLayout: 'layouts', layoutsDir: dirname + '/views/layouts/'})); app.set('views', path.join(dirname, 'views')); app.set('view engine', 'hbs');

// uncomment after placing your favicon in /public //app.use(favicon(path.join(dirname, 'public', 'favicon.ico'))); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(expressValidator()); app.use(cookieParser()); app.use(express.static(path.join(dirname, 'public'))); app.use(expressSession({secret: 'max', saveUninitialized: false, resave: false}));

app.use('/', routes);

// catch 404 and forward to error handler app.use(function(req, res, next) { next(createError(404)); });

// error handler app.use(function(err, req, res, next) { // set locals, only providing error in development res.locals.message = err.message; res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page res.status(err.status || 500); res.render('error'); });

module.exports = app;