Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

96
Visualizações
ypeError: exports.getAllProducts is not a function

I have created a file productcontroler.js where i have placed the function which is runign on routes call

exports.getAllProducts() = (req,res)=>{
  res.status(200).json({message:"Route is working fine"});
}

and here is the route

const express = require("express");
const {getAllProducts} = require("../controller/productController.js")

const router = express.Router();


router.route("/product").get(getAllProducts);

and i am getting this error

exports.getAllProducts() = (req,res)=>{
        ^

TypeError: exports.getAllProducts is not a function

after removing the parantheses from getAllproduct in controller file

hrow new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
      ^

TypeError: Router.use() requires a middleware function but got a Object
    at Function.use (C:\Users\saran\OneDrive\Desktop\Learn React\mern\node_modules\express\lib\router\index.js:464:13)
    at Function.<anonymous> (C:\Users\saran\OneDrive\Desktop\Learn React\mern\node_modules\express\lib\application.js:220:21)      
    at Array.forEach (<anonymous>)
    at Function.use (C:\Users\saran\OneDrive\Desktop\Learn React\mern\node_modules\express\lib\application.js:217:7)
    at Object.<anonymous> (C:\Users\saran\OneDrive\Desktop\Learn React\mern\backend\app.js:13:5)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

you might be forgetting to export one of your files like your router

if you are using const router = express.Router();

don't forget to export module.exports=router;

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda