Q: nodeJS TypeError: result is not a function I'm currently learning nodeJS with express and mySQL. I'm currently following this tutorial: https://bezkoder.com/node-js-rest-api-express-mysql/
when testing my api it logs all projects correctly to the console but then my app crashes with this error:
"TypeError: result is not a function"
This is my code:


const sql = require('./db.js');

// Constructor
const Project = function(project) {
    this.name = project.name;
    this.desc = project.descript;
    this.github = project.github;
}

Project.getAll = result => {
    sql.query("SELECT * FROM project", (err, res) => {
      if (err) {
        console.log("error: ", err);
        result(null, err);
        return;
      }
  
      console.log("projects: ", res);
      result(null, res);
    });
};

module.exports = Project;


project.controller.js


const Project = require("../models/project.model.js");

// Create and Save a new Project
exports.create = (req, res) => {
    // Validate request
    if (!req.body) {
      res.status(400).send({
        message: "Content can not be empty!"
      });
    }
  
    // Create a Project
    const projects = new Project({
      name: req.body.name,
      desc: req.body.descript,
      github: req.body.github
    });
  
    // Save Project in the database
    Project.create(projects, (err, data) => {
      if (err)
        res.status(500).send({
          message:
            err.message || "Some error occurred while creating the projects."
        });
      else res.send(data);
    });
  };

// Retrieve all Projects from the database.
exports.getAll = (req, res) => {
    Project.getAll((err, data) => {
        if (err)
          res.status(500).send({
            message:
              err.message || "Some error occurred while retrieving projects."
          });
        else res.send(data);
      });
};


project.routes.js


const Project = require("../models/project.model.js");

module.exports = app => {
    const project = require("../controllers/project.controller.js");
  
    // Create a new Project
    app.post("/projects", project.create);
  
    // Retrieve all Projects
    app.get("/projects", Project.getAll);
  };


I checked the full tutorial a couple times to find out what might be the reason and checked the comments under the tutorial. I also tried using google to find a solution for this but didn't had much luck yet.

A: I solved this issue. It was a typo within my project.routes.js file.
// Retrieve all Projects
    app.get("/projects", Project.getAll);

should be
// Retrieve all Projects
    app.get("/projects", project.getAll);


A: It might help someone who is new to NodeJS just like me.
I had the same issue. Maybe the OP and I, both referred to the same article. In my case, I was passing 2 parameters to the function, because of which the result parameter is undefined (hence not a function) and it cannot be called.
Replaced the first line of the below code (function call with two parameter) -
User.getAll = (userId, result) => {
    ...
};

with function with one parameter
User.getAll = result => {
    ...
};

