"Throw new typeerror('router.use() requires a middleware function but got a ' + gettype(fn))" (Code Answer's)

We have a very easy explanation of the problem. When you make an API using node, express, and MySQL, suddenly you receive an error that is:

throw new TypeError(‘Router.use() requires a middleware function but got a ‘ + gettype(fn))

The first mistake that you are making is using app.use() rather than app.set(). You are entering a string or any number to app.use() and looking for middleware function reference that's why the error is coming.

The second mistake you are making is overloading app.use().

TypeError: Router.use() requires a middleware function but got a Object

on Jan 01, 1970
module.exports = router;

Add Comment

0

TypeError: app.use() requires a middleware function

on Jan 01, 1970
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');

const app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());

// tells express which template engine to use
app.set('view engine', 'pug');

const routes = require('./routes');

app.use(routes);

app.use((req, res, next) => {
    console.log('Hello');
    next();
});
app.use((req, res, next) => {
    console.log("World");
    next();
});

app.use((req, res, next) => {
    const err = new Error('Not Found');
    err.status = 404;
    next(err);
});

app.use((err, req, res, next) => {
    res.locals.error = err;
    res.status(err.status);
    res.render('error');
});

app.listen(3000, () => {
    console.log('The application is running on localhost 3000');
});

Add Comment

0

You may also solve your problem by adding modules exports router; at the last end of every route file. That error may occur when route modules are not entered which are used by the routers. It means you have not allowed express to recognize all routes

Go answers related to "Throw new typeerror('router.use() requires a middleware function but got a ' + gettype(fn))"

View All Go queries

Go queries related to "Throw new typeerror('router.use() requires a middleware function but got a ' + gettype(fn))"

Throw new typeerror('router.use() requires a middleware function but got a ' + gettype(fn)) TypeError: Router.use() requires a middleware function but got a Object TypeError: __init__() got an unexpected keyword argument 'enable camera feed' TypeError: search() got an unexpected keyword argument 'tld' Expected 2 arguments, but got 1.ts(2554) core.d.ts(7888, 47): An argument for 'opts' was not provided. Expected 1 arguments, but got 0. Expected response code 250 but got code "501", with message "501 5.5.4 Invalid domain name csgo jump throw bind throw grenade again csgo gin middleware example gin middleware redirect ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216 from C header, got 192 from PyObject how to tell if you got pygAME ValueError: not enough values to unpack (expected 3, got 2) pdo how to check if got any row - Workspace.Arrow.GettingStands:24: Expected 'then' when parsing if statement, got 0061:err:rpc:I_RpcReceive we got fault packet with status 0x80010108 the action run applescript encountered an error : "finder got an error: you don't have permission to create a file here render_to_response() got an unexpected keyword argument 'context_to_response' i got a really nice cable and a set of keycaps more mthis keyboard, sssssssdasdfasddddxx bbbsdfbsdfbsdfbsdf i got guns in my head and they won't go read_csv() got an unexpected keyword argument 'columns' golang flagset check to see if arg is available but has no value im going from first screen to second and from there to third but dont want to go back in flutter This release is not compliant with the Google Play 64-bit requirement The following APKs or App Bundles are available to 64-bit devices, but they only have 32-bit native code: 3. site:stackoverflow.com how to go back in usinsg router hisotry golang new new line in google sheet cell go create new instance of struct how to make a div text don't go to the new line create new grepper code for search in google mongo query new id Is it a good idea to use .svg images in web design? create, use and destroy a 2d array what is the use of map in golang golang function Golang test function function change(cash) { // Your code goes here return { two: 0, five: 0, ten: 0 }; } what is the update function in godot? golang high order function example golang recursive function example sql window function advantages

Browse Other Code Languages

CodeProZone