Home > Net >  Cannot Passing Express Js Router Request and Respond to Class Method
Cannot Passing Express Js Router Request and Respond to Class Method

Time:11-25

I have a problem when creating express JS router.

I can not passing req and res to my class method.

Not Work app.get('/', controller.index)

Work app.get('/', (res,req) => controller.index(req,res)

The following is the flow of the routing that I made:
app.js (Main file) > /routes/index.js > /routes/user.route.js > /controllers/user.controller.js > /services/user.services.js

app.js

import express from 'express';
import cors from 'cors';
import routes from './routes';
import db from './models';
import dotenv from 'dotenv';

dotenv.config();
const app = express();
const port = process.env.PORT || 3001;

app.use(cors())
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

// Database Initialize
db.sequelize.sync()
.then(() => {
    console.log("           
  • Related