I continue to encounter the following error message: Error: Route.post() expects callback functions but received an [object Undefined]

Currently, I am in the process of setting up a react express application that utilizes mongo db as its database. During the initial stages, I keep encountering this particular error message:

 Error: Route.post() requires callback functions but got a [object Undefined]

Below is my app.js file for reference:

const express = require('express');
// const http = require('http');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const app = express();
const mongoose = require('mongoose');

mongoose.Promise = global.Promise;


//db  and name is auth

mongoose.connect('mongodb://localhost/auth', {
    useMongoClient: true,
    /* other options */
  });
// app setup

//server setup

const port = process.env.Port || 4000
// const server = http.createServer(app);
app.listen(port);
console.log(`Sever listening on ${port}`)

const authRoutes = require('./routes/auth_routes');
app.use('/',authRoutes); 

My routes are implemented as follows. I am currently testing to confirm a valid connection.

const authController = '../controllers/auth_controller';
const express = require('express');
const authRoutes = express.Router();


    authRoutes.post('/',authController.signup)



module.exports = authRoutes;

The controller logic is outlined below:

const authController = {};

authController.signup = function(req,res,next) {
    console.log('here');
    res.json({
        user: "doesnt matter",
        data: 'Put a user profile on this route'
      });
}

module.exports = authController;

I am uncertain if the issue lies with mongo since this is my first time utilizing it. However, my database connection appears functional as Robo 3T shows the relevant user schema stored within the database. Interestingly, when I comment out a specific route in the routes page, the errors cease.

Answer №1

It appears that the issue lies in this section:

const authentication = '../controllers/auth_control';

routes.post('/',authentication.signup)

Please take note that authentication is currently a string value. It seems like you meant to use:

const authentication = require('../controllers/auth_control');

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can you guide me on how to export a named function using module.exports?

I have a script file for my discord bot that includes a specific command and a function with parsing logic that I want to reuse in my main index.js // File: ./commands/scrumPrompt.js // The function const extractDeets = function (f, scrum) { let items ...

The email verification link page API encountered an error as the server responded with a status of 400 (Bad Request), leading to the failure in loading the resource

After confirming that the backend is working smoothly with Postman, I encountered an issue when running the code on the client side. The error message states: "Failed to load resource: the server responded with a status of 400 (Bad Request)" The following ...

Implementing parallel HTTP requests with a dynamic number of requests using RxJs

Currently, I am in the process of building a Node.js API that utilizes Express. As part of this project, I am incorporating the node-rest-client module to handle HTTP requests. One of the key API endpoints that needs to be developed is /api/v1/users/:user ...

Tips for properly configuring a session with everyauth and express

I've been working on a simple nodejs application that allows users to log in with Facebook using express and everyauth. I followed the instructions provided in the README tutorial here and set up my app.js file as shown below: var everyauth = require ...

Retrieve events from Microsoft Outlook calendar by utilizing the Graph API with Node.js

I am currently working on developing a user-friendly calendar application specifically designed to display calendar events for Microsoft Outlook users. For authentication, I have integrated @azure/msal-node. To fetch events, I am utilizing the GET https: ...

npm fails to function properly following the execution of the 'npm install' command

After downloading and installing node.js + npm from https://nodejs.org/en/, I created a project folder and navigated into it on Windows 10. However, when I attempted to run the command: C:\nodejs\demo>npm install <a href="/cdn-cgi/l/email- ...

We are sorry, but the requested route cannot be located

I'm diving into the world of express and trying to set up subroutes for a specific "plan" with corresponding actions. My journey begins at mypage.com/someroute/123321312 router.get('/:planId', function(req, res, next) { //a form is render ...

What could be causing an issue with CORS in ExpressJS in one scenario but not in another?

I am currently in the process of setting up a database and connecting it to various routes. Interestingly, I have been successful with one route ('register') but encountering issues with another ('login'). Whenever I attempt to run the ...

What is the process of embedding an image URL in a database table?

Currently, I am facing an issue with uploading photos via Cloudinary and inserting the photo URL into my database table to save them on the page. Even though my route is configured correctly and not crashing the server, it seems that the data is not bein ...

Combining Multiple JSON APIs on One Page [Using Node.js]

Is there a way to retrieve data from two APIs ('url' and 'url_test') and display it on a single page ('index.ejs') using Nodejs and Express? I have tried implementing Async and Promise, but haven't found the right solutio ...

How does the JSON data get served when Node.js is collaborating with CouchDB and Backbone.js?

Transitioning from a WordPress background to learning Node.js for a test app has been challenging. While Apache took care of most backend logic before, I'm now tasked with building it all myself. My main question revolves around serving JSON files fro ...

Tips for storing the outcome of a MySQL query in ReactJs?

I am working on a ReactJs code where I have a SELECT statement. The request is functioning correctly, but now I want to store the result into a variable. How can I achieve this? let result; async function fetchSubsystems() { return Axios ...

What could be causing the issue with creating new comments in my node.js application?

I am encountering an issue while attempting to add a new comment in my node.js application. Specifically, I am trying to create a comment under specific posts using the post's path. Below are the relevant parts of my code: Comment Model const mongo ...

An unparalleled nextjs middleware that seamlessly functions across all routes without requiring individual imports

TLDR; A middleware similar to express for Next.js where I can define it once and have it automatically apply to all routes. I am looking for a middleware style like what we have in express. Ideally, I would define the middleware in the server.js (entry f ...

The expression req.files consistently comes back as an empty [object]

I have been encountering an issue with saving uploaded files using their original names (with express-fileupload). Whenever I upload a file, it gets saved in the directory as [object Object]. Node: var express = require('express') var app = exp ...

Web application using node.js with rendering on the client side

Currently working on my first web application using node.js and exploring the world of express framework. One query I have is regarding client side rendering. All the resources available online focus mainly on server side rendering with express and how yo ...

Angular Application Functions Properly on Local Machine, Yet Experiences Issues When Deployed on Azure

I've been making the transition from AngularJS to Angular 2 and beyond. I found a tutorial that helped me set up routing with multiple components using Visual Studio IDE, which worked flawlessly on my local machine: However, when I tried to publish i ...

Passport causing problems in route configuration

I'm currently developing a web application using NodeJS, Express, and PassportJS. I've encountered an issue with one of my routes that is quite perplexing to me. Initially, I have the following code: ... app.get('/auth/facebook', passp ...

Issue with Promise rejection not being caught in Node.js with ExpressNode.js and Express are not

Within my Express web application, I've created a function that outputs a Promise object. login: function(un, pass) { result = {}; var loginOk = new Promise( function (resolve, reject) { if (result.hasOwnPr ...

POST method is not permitted on Expressjs 405

While the route functions perfectly in POSTMAN's chrome extension, it doesn't seem to work with Angular. Here is my Express js code : var express = require('express'); var router = express.Router(); var app = express(); var bodyParse ...