Route.get() function is expecting a callback function, but instead received a string object

Having searched through similar posts, I am unsure and lack the experience to apply the suggested resolutions to my project. I recently built a basic app with two main routes as part of a Udemy course, but I am struggling with the following error: "Route.get() requires a callback function but got a [object String]". While I understand the concept of exporting a router object with nested routes for a root route, the request for a callback in this context is confusing. The error originates from the route.js file within the node_modules library at node_modules\express\lib\router\route.js:211:15.

I attempted to create a new test controller, only to encounter the same issue even without importing any route files. When I deleted the route.js file from the library, a new error emerged stating: "Cannot find module './route'." It seems that I have hit a dead end.

I would greatly appreciate any insights and suggestions to resolve this issue. Below, I have included the route, controller, and package.json files for reference:

Controller (app.js)

// Code snippet provided

//================================================================================================== Route file (campRoutes.js)

// Code snippet provided

//==================================================================================================

package.json file

{
  "name": "yelpcamp",
  "version": "1.0.0",
  // Other package details
}

Answer №1

There is a small error in your views engine configuration. Ensure to update it like this:

app.set('view engine', 'ejs')

Replace get with the correct command.

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

Issue with setting HTML content using jQuery's .html() method

I have a simple functionality. When a user clicks on the edit link, it transforms the previous element into an input element for editing, and changes the edit link into a cancel link. If the user decides not to edit, they can click on cancel and everything ...

Using AngularJS to bind models to a multidimensional array

As I am new to angular js, please bear with me. In my view, I have a grid of text input boxes that I would like to map to a 2D array in my controller or something similar in java script. The code in my view is as follows: <div ng-repeat="row in [1,2,3, ...

Strange behavior: JS object values disappear when accessed statically

I'm feeling puzzled. The issue at hand is that an object seems to lose its values within a loop based on the method of access. When accessed through variables, everything appears to be in order. However, when using static expressions identical to the ...

Whenever attempting to access an array within a MongoDB result object, there is always the potential for encountering

Hey there! I could really use some assistance with setting up a basic login/authorization system for my personal site built on Express.js. The login functionality is powered by Password.js and is functioning properly, but I'm encountering an issue wit ...

Providing parameters to a dynamic component within NextJS

I am dynamically importing a map component using Next.js and I need to pass data to it through props. const MapWithNoSSR = dynamic(() => import("../Map"), { ssr: false, loading: () => <p>...</p>, }); Can anyone sugges ...

Using ReactJS to display a collection of images

Currently diving into ReactJS and experimenting with the Spotify API, everything is running smoothly except for a hurdle I encountered while attempting to display an array of images retrieved from the API. I initially tried to render the images inside the ...

Steps to substituting characters within a date string

Create a function called normalize that changes '-' to '/' in a given date string. For example, normalize('20-05-2017') should output '20/05/2017'. This is my attempt: let d = new Date('27-11-2021'); fun ...

Middleware that is commonly used by both error handling and regular request-response chains

I am currently working on implementing a middleware that can set a variable in the sequence of both error and non-error scenarios. Is there a way to achieve this without disrupting the normal flow of middleware? Specifically, when I include the err param ...

Managing errors in jQuery's .ajax function

Having some issues with jQuery.ajax() while trying to fetch an html code snippet from table_snippet.html and replacing the element in my html code. The error handler in jQuery.ajax() gets triggered instead of the expected success handler. <!DOCTYPE H ...

Are there any find all functions available in JavaScript that are built-in?

I frequently work with arrays in JavaScript, and I am facing an issue with the function .find() as it only returns the first occurrence. I need a way to get all occurrences if there are multiple. Below is my code: const condition = [ { info_p ...

Exploring Angular 2 Application Testing: Tips for Interacting with HTML Elements

In my Angular 2 Frontend testing journey, I came across a blog post ( ) where the author utilized ng-test TestBed for core testing in Angular. While the example provided was helpful for basic understanding, it lacked details on how to manipulate Elements. ...

When using the Parse JS SDK with AngularJS UI routing, the login functionality may not properly retain the current user's

Below is the configuration and initialization of my module: angular.module('FXBApp', [ 'ui.bootstrap' ,'ui.router' ,'oc.lazyLoad' ,'parse-angular' ]). config(['$urlRouterProvider','$statePro ...

Implement pre-save middleware in Mongoose to perform lowercase validation on a document's

In order to have a user object maintain case sensitivity for display purposes, while being lowercased for uniqueness purposes, I initially considered adding a usernameDisplay property to the schema with a pre-save hook: var userSchema = new Schema({ u ...

Navigate back to the parent directory in Node.js using the method fs.readFileSync

I'm restructuring the folder layout for my discord.js bot. To add more organization, I created a "src" folder to hold all js files. However, I'm facing an issue when trying to use readFileSync on a json file that is outside the src folder. Let&ap ...

Guide on implementing factory updates to the display

I am attempting to update a reference within my factory in an asynchronous fashion, but I am not seeing the changes reflected in my view. View <div ng-repeat="Message in Current.Messages">{{Message.text}}</div> Controller angular.module(&ap ...

Utilizing Material UI (mui) 5.0 within an iframe: Tips and tricks

Attempting to display MUI components within an iframe using react portal has resulted in a loss of styling. Despite being rendered within the iframe, MUI components seem to lose their visual appeal when displayed this way. Most resources discussing this is ...

Moving the panel to follow the mouse cursor in Firefox Add-on SDK

Is there a way to show a panel on the screen at the exact position of the mouse? I'm finding it difficult to understand how to change the position of the panel in Firefox SDK, as the documentation lacks detailed information. ...

Wait until the npm.load callback is returned before returning module.exports

I am currently facing a situation similar to the one depicted in this simplified example. main.js var settings = require('../settings.js'); console.log(settings.globalData); //undefined The settings.js file relies on an external module (npm) t ...

Feathers.js - Incorporating Static Content

Recently, I've been exploring the capabilities of feathers.js for a new project and have been quite impressed with its potential. Intrigued by what it offers, I decided to embark on creating a basic content management system as a way to further my lea ...

Locate relevant information within the arrays through the process of filtering

For my collection, I am looking to match the operator_name based on date and then further narrow it down by matching shift_name within an array { "_id": "5eb301bc0218ff48b724a486", "date": "2020-07-02T00:00:00.000Z", "shift_wise": [{ "_id": ...