Encountering a TypeError indicating that the asterisk is not functioning as a proper function

Whenever I run my server.js file, an error keeps popping up:

TypeError: routing is not a function

This occurs in the following line of code:

routing(app);

In my routing.js file, the content looks like this:

// JavaScript source code
var friends = require('./../controllers/friends.js');

module.export = function(app)
{...}

Answer №1

Exporting the module incorrectly is a common mistake. Instead of using "exports", make sure to use module.exports. The error message you are receiving indicates that the calling module cannot find the function you are trying to access, resulting in an undefined value being returned.

// JavaScript source code
var friends = require('./../controllers/friends.js');

module.exports = function(app)
{...}

For more information on this topic, you can refer to:

Stack Overflow - module.exports
Node.JS Module Docs

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

Subpar resolution of PNG images displayed in HTML canvas

My attempt to draw a PNG image onto the canvas is resulting in poor quality. I am using the drawImage method as shown below: src = folder+self.cur+".png"; imageObj.src = src; imageObj.onload = function() { context.clearRect(0, 0, cv, ch), context.drawImag ...

using express to display events and gatherings from external websites

I've created a simple Express application with a single function that utilizes the nodejs request and selects specific div elements. My goal is to then render this using jade. var express = require('express'); var voc = require('vocabu ...

The issue of not being able to go fullscreen with a YouTube iframe nested within another iframe

I have a YouTube video embedded inside another iframe, but I am facing an issue where the fullscreen feature is not working even after enabling all the required attributes. If the video isn't displaying properly in the code snippet below, you can vie ...

How can one effectively extract data from a database in a React application?

We have a basic react app with authorization, utilizing JWT tokens and Redux for state management. Personally, I find the code quite complex and obfuscated, making it challenging to grasp fully. However, let's set that aside. Upon login, a token is s ...

Can anyone suggest methods for displaying query data from a JSON file using HTML?

After countless hours of searching through various forums, I have attempted numerous methods to display query data from a JSON file onto an HTML page. My initial attempt was using XmlHttpRequest, which yielded no results. I then tried utilizing jQuery, sp ...

In Angular, the ng-click directive that assigns the value of tab to $index does not seem to be functioning properly

I encountered an issue within my app <li ng-repeat="name in tabs track by $index" ng-class="{selected: tab==$index}" ng-click="tab = $index">{{name}}</li> After clicking on each item, the selected class remains enabled and switching to anothe ...

How to flip the value in v-model using VueJS

Below is the code snippet that I am working with: <input v-model="comb.inactive" type="checkbox" @click="setInactive(comb.id_base_product_combination)" > I am looking to apply the opposite value of comb.inactive to the v-model. Here are m ...

Sequelize - utilizing the where clause with counting

I have three models that extend Sequelize.Model and I have generated migrations for them. The associations are set up as follows: Cat Cat.belongsToMany(Treat, { as: 'treats', through: 'CatTreat', foreignKey: 'cat_id', } ...

Express server controller encountering premature return from locally executed async function

I have developed an API endpoint using Node/Express. I am trying to call a local function asynchronously within the controller function, but instead of receiving the expected asynchronous results, the called local function is returning undefined immediat ...

`"error_message":"Failed to process request with status code 500","error_type":"ServerError","error_stack":"ServerError: Failed to process request with status code 500 ``

For my project, I needed to retrieve data from an open API using the following link. As per the documentation, the HTTP method required is POST and the Content-Type should be either "application/graphql" or "application/json". I implemented a node express ...

Steps to create a new window using Raphael JS

Is there a way to create a new window in Raphael similar to using "_blank"? ...

Authentication with Express, Passport, and JSON Web Token (JWT)

When trying to access the "/secret" endpoint with a valid JWT token using passport authentication, the response returns a message saying "Success! You can not see this without a token". I will test this in Postman with the following authorization credenti ...

How can I ensure that the package-lock file, integrity SHAs, and locally built modules packaged as tgz files all function harmoniously together?

Imagine this scenario: We have certain modules that we install as tgz files. In our package.json, these modules are referenced like this: "somePackage": "file:../modules/somePackage.tgz", We want to utilize package-lock files for bet ...

Is the JSON parsing issue being caused by Bodyparser?

I am encountering an issue with parsing JSON on my server using the body-parser NPM module and Express. The JSON data is not appearing correctly on the server for some reason. Here is a snippet of my server code: ... app.use(bodyParser.json()); app.use(bo ...

Sending two arguments to an Express Mongoose API in order to fetch a singular outcome

I'm currently exploring the world of developing APIs using Express and Mongoose. Setting up basic endpoints for get, post, put has been a breeze so far. Now, I'm eager to create an endpoint where I can pass two parameters to search a collection ...

Improving performance in Next.JS by optimizing unused JavaScript resources

Currently working on my first website using Next.js and experiencing poor performance scores after running a lighthouse test. The issue seems to be related to unused JavaScript files located in the chunk folder. I've come across suggestions to split t ...

It appears that the query parameters are impacting the speed at which the page loads

I am currently developing a project on this platform. It is using c9.io, an innovative browser-based collaborative programming IDE. The index.php file includes the following script: <?php $path = ltrim($_SERVER['REQUEST_URI'], '/&ap ...

Vue.js: Select a different div within the Vue object instead of the one that is bound

I am currently utilizing Vue and Leaflet to showcase polygons (zones) on a map and exhibit relevant information (messages) upon clicking on specific polygons. The div responsible for rendering these messages has the unique id "#messagearea" and is connec ...

What is the best way to identify and recover two separate client socket connections from the same user after a server restart?

Picture this scenario: A customer opens a browser tab and goes to page-x. As the customer remains on this page, I send out data through a socket specific to this page, which we'll call socket-context-x. Next, the customer opens another browser tab ( ...

The function res.sendfile() is not effective in serving Javascript files

I am looking to serve static files without using a rendering engine. I have attempted to use: res.sendfile('public/index.html'); for the '/' GET route, and I've set up express middleware for serving static files on my route: app ...