Search code examples
javascriptnode.jsyeomanmulterangular-fullstack

Possible issue with multer? Error: Router.use() requires callback


Building a site with yeoman angular-fullstack works great locally, but when I deploy and use the dist/release version it gives me this fun error on my server.

Error: Router.use() requires callback functions but got a [object Object]
at Function.proto.use (/home/bitnami/htdocs/dist/node_modules/express/lib/router/index.js:327:11)
at Object.<anonymous> (/home/bitnami/htdocs/dist/server/api/save/index.js:10:8)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.<anonymous> (/opt/bitnami/nodejs/lib/node_modules/pm2/node_modules/pmx/lib/transaction.js:62:21)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at module.exports (/home/bitnami/htdocs/dist/server/routes.js:13:25)

It seams that it's failing on this line

router.use(multer({ dest: './public/uploads/'}));

Though it works locally completely fine? Has me a bit stumped. Wonder if its related to multer? I have the node module installed. Thoughts?


Solution

  • Recent versions of multer changed the API. If you look at the examples, you will see you now have to do something like:

    var upload = multer({ dest: './public/uploads/'});
    
    // ...
    
    router.use(upload.single('foofield'));
    

    Or upload.array() or upload.fields().