Reputation: 15
im using express and es6 and im trying to route in this way..
index.js
import express from 'express'
import bodyParser from 'body-parser'
import appRoutes from './routes/appRoutes.js'
var app = express();
app.use(express.urlencoded({extended:false}));
app.use(bodyParser.json());
app.use(express.json());
app.use('/api', appRoutes);
app.get('/', (req, res) => res.send("hellow express"));
app.listen(PORT, () => console.log(`Server runing on port : http://localhost:${PORT}`));
appRoutes.js
import express from 'express'
import {hello, sendMessage} from '../controllers/appController.js'
const appRoutes = express.Router();
appRoutes.get('/', hello);
appRoutes.post('/', sendMessage);
export default {appRoutes};
but run through this error..... Router.use() requires a middleware function but got a Object
Upvotes: 0
Views: 257
Reputation: 26
in appRoutes.js file, change this
export default {appRoutes};
into
export default appRoutes;
Upvotes: 1
Reputation: 92
maybe you can try to redo importing and exporting in a similar way:
Only I think you don't need to pass and handle the db variable like I do
Upvotes: 1