Reputation: 23
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");
});
Upvotes: 2
Views: 2080
Reputation: 12081
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();
Upvotes: 1