-1

This is the error:

 throw new TypeError('app.use() requires a middleware function')
    ^

TypeError: app.use() requires a middleware function
    at Function.use (/Users/Andres/Desktop/chat-app-2/server/node_modules/express/lib/application.js:210:11)
    at Object.<anonymous> (/Users/Andres/Desktop/chat-app-2/server/index.js:13:5)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47
[nodemon] app crashed - waiting for file changes before starting...

ROUTER.JS

    const express = require('express');
    const router = express.Router();
    
    router.get(`/`, (req, res) => {
        res.send('server is up and running');
    });
    
    module.export = router;

INDEX.JS

    const express = require('express');
    const socketio = require('socket.io');
    const http = require('http');
    
    const PORT = process.env.PORT || 5000;
    
    const router = require('./router');
    
    const app = express();
    const server = http.createServer(app);
    const io = socketio(server);
    
    app.use(router);
    
    server.listen(PORT, () => console.log(`Server has started on port ${PORT}`));

Can someone help me with these?

Christian Fritz
  • 20,641
  • 3
  • 42
  • 71

1 Answers1

0

According to https://expressjs.com/en/guide/routing.html you need to provide a route where the imported router is support to run. Try:

app.use('/', router);

or you can use a different route, like /mysubroute.

Christian Fritz
  • 20,641
  • 3
  • 42
  • 71