unable to start app in node.js getting the following error -


welcome git (version 1.9.5-preview20150319)

run 'git git' display index. run 'git ' display specific commands.

$ npm start

nodeauth@1.0.0 start c:\users*****\desktop\nodeauth node ./bin/www

c:\users***\desktop\nodeauth\node_modules\express\lib\application.js:206 throw new typeerror('app.use() requires middleware functions'); ^

typeerror: app.use() requires middleware functions @ eventemitter.use >>...>

//app.js

var express = require('express'); var path = require('path'); var favicon = require('serve-favicon'); var logger = require('morgan'); var expressvalidator = require('express-validator'); var cookieparser = require('cookie-parser'); var session = require('express-session'); var passport = require('passport'); var localstrategy = require('passport-local').strategy; var bodyparser = require('body-parser'); var multer = require('multer'); var flash = require('connect-flash'); var mongo = require('mongodb'); var mongoose = require('mongoose'); var db = mongoose.connection;   var routes = require('./routes/index'); var users = require('./routes/users');  var app = express();  // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade');  // handle file uploads app.use(multer({dest:'./uploads'}));  // uncomment after placing favicon in /public //app.use(favicon(__dirname + '/public/favicon.ico')); app.use(logger('dev')); app.use(bodyparser.json()); app.use(bodyparser.urlencoded({ extended: false }));  //handle express sessions app.use(session({   secret:'secret',   saveuninitialized: true,   resave:true }));  // passport app.use(passport.initialize()); app.use(passport.session());  // validator app.use(expressvalidator({   errorformatter: function(param, msg, value) {       var namespace = param.split('.')       , root    = namespace.shift()       , formparam = root;      while(namespace.length) {       formparam += '[' + namespace.shift() + ']';     }     return {       param : formparam,       msg   : msg,       value : value     };   } }));  app.use(cookieparser()); app.use(express.static(path.join(__dirname, 'public')));  app.use(flash()); app.use(function (req, res, next) {   res.locals.messages = require('express-messages')(req, res);   next(); });  app.use('/', routes); app.use('/users', users);  // catch 404 , forward error handler app.use(function(req, res, next) {   var err = new error('not found');   err.status = 404;   next(err); });  // error handlers  // development error handler // print stacktrace if (app.get('env') === 'development') {   app.use(function(err, req, res, next) {     res.status(err.status || 500);     res.render('error', {       message: err.message,       error: err     });   }); }  // production error handler // no stacktraces leaked user app.use(function(err, req, res, next) {   res.status(err.status || 500);   res.render('error', {     message: err.message,     error: {}   }); });   module.exports = app; 

you need use app.use(multer({dest:'./uploads/'})) in form of 1 of these:

app.use(multer({dest:'./uploads/'}).single(...)); app.use(multer({dest:'./uploads/'}).array(...)); app.use(multer({dest:'./uploads/'}).fields(...)); 

ie:

app.use(multer({dest:'./uploads/'}).single('photo')); 

and sure have like:

<form action="/postphotos" enctype="multipart/form-data">     <input type="file" name="photo">     <input type="submit" value="upload photo"> </form> 

in html.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -