question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: app.use() requires middleware functions

See original GitHub issue

this is the example code:

app.use logger 'dev'
app.use bodyParser.json()
app.use bodyParser.urlencoded()
app.use multer inMemory: yes

when it executes, throw an TypeError from app.use multer: inMemory: yes:

TypeError: app.use() requires middleware functions
    at EventEmitter.use (/Users/ran/github/lbs-app/node_modules/express/lib/application.js:206:11)
    at Object.<anonymous> (/Users/ran/github/lbs-app/app.js:69:7)
    at Object.<anonymous> (/Users/ran/github/lbs-app/app.js:108:4)
    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 Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/ran/github/lbs-app/bin/www:7:11)
    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.Module.runMain (module.js:501:10)
    at startup (node.js:124:16)

I was confused at first, because the same code works well on my laptap, and when I check the dependencies’ version, I found multer: 0.1.8 => 1.0.1

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

31reactions
LinusUcommented, Dec 18, 2017

@sagarpandav Could it be that you have forgot to do module.exports = in your routes/index.js file?

3reactions
macneibcommented, Jul 21, 2015

So I’m thinking you had the same problem as me. I had my multer configuration in my express config file, so now I’m rushing a fix to get it nested in to a route.

for example: in my routes.js file

module.exports = function(app) {
<-SNIP->
  app.use('/api/uploads', require('./api/upload'));
<-SNIP->
};

and in /api/uploads/index.js

'use strict';
var express = require('express');
var controller = require('./upload.controller');

var multer = require('multer');
var os = require('os');
var uuid = require('node-uuid');
var storage = multer.diskStorage({
  destination: function (req, file, cb) { cb(null, os.tmpdir()) },
  filename: function (req, file, cb) { cb(null, uuid.v4());}
});
// Create the multer instance here
var upload = multer({ storage: storage, limits: { fileSize: 10 * 1024 * 1024}});

var router = express.Router();

// File Upload route
router.post('/', upload.single('file'), controller.upload);

module.exports = router;

I’m still finishing up my code, but that’s a rough idea of what the change is. Good luck!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: app.use() requires middleware functions
app.use requires that you pass it a function which is then used as middleware. You have two instances where you do not do...
Read more >
TypeError: app.use() requires middleware functions - Treehouse
use() requires middleware functions. For some reason, I'm getting this error even though it looks like my code matches the instructor's. app.js.
Read more >
typeerror: router.use() requires a middleware function but got ...
node app. The error is. TypeError: Router.use() requires middleware function but got a Object. And tracing the error leads me to line 32...
Read more >
TypeError: app.use() requires a middleware function
"typeerror: app.use() requires a middleware function". Add Answer | View In TPC Matrix. Technical Problem Cluster First Answered On April 26, ...
Read more >
Router.use() requires a middleware function but got a Object ...
TypeError : Router. use() requires a middleware function but got a Object | Node Js error. 10K views 1 year ago.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found