2

I made a NodeJS application which usere a static Method to do some calculation Function. When i try to acces the Method i got the isNotAFunction Error.

Here a static class which causes the error while accessing it:

exports.module = class PlaceEvaluator
{
    static testMethod()
    {
        console.log("Test");
    }
}

Here is the Code of the file which throws the Exception while reading:

PositionFinder = require("./positionFinder.js");
PlaceObj = require("./placeObj.js");
PlaceEvaluator = require("./placeEvaluator.js");
fetch = require("cross-fetch");
const express = require("express");
const http = require("http").createServer(express);
const io = require("socket.io")(http, {
    cors:{
        origin: "*"
    }
});



const application = express();

application.use(express.static("public"));

PlaceEvaluator.testMethod();

io.on("connection", socket => {
    socket.on("placeQuery", async ({topic, lat, long}) => {
       
        PlaceEvaluator.testMethod();  //Here is the Exception function call 
       
        //console.log("Response sent!");
    })
})

async function findPlaceObject(type, lat, long)
{
    let placeObj = await PositionFinder.FetchPosition(type, lat, long);
    return placeObj;
}

function convertToPlaceObjArr(inputObj)
{
    var outputArr = [];

    let name;
    let lat;
    let long;
    

    for(var i = 0; i < inputObj.results.length; i++)
    {
        name = inputObj.results[i].name;
        lat = inputObj.results[i].geometry.location.lat;
        long = inputObj.results[i].geometry.location.lng; 
        outputArr.push(new PlaceObj(name, lat, long));
        console.log(inputObj.results[i].name);
    }

    return outputArr;
}


http.listen(4000, function(){
    console.log("Running on Port 4000");
    // PositionFinder.FetchPosition("Pizza", "51.896359", "6.982303");
});

1 Answer 1

1

You need to use module.exports to export a default rather than exports.module.

By using exports.module you are exporting your class with the key of module so in that case you would have to do:

PlaceEvaluator.module.testMethod();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.