-1

I am trying to call a function in loopback model.js file called models/customerProfile.js from a JS file server/script/myScripts.js but I am getting this error:

Unhandled error for request GET /api/CustomerProfiles/verifyCustomer?id=38733: TypeError: myScripts.verifyCustomerProfile is not a function

I want to keep all my generic functions in this myScripts file and call them from my model.js files.

I did the following in my customerProfile.js model file to include the script:

var myScripts = require('../../server/script/myScripts');

then in my code I referenced it as follows:

myScripts.functionName();

It doesn't work.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Oct 16 '17 at 14:56

1 Answers1

0

Did you export your functions ?

myScripts.js

Try this one :

module.exports = {

functionName : function() {
 // Your code
},

functionName2 : function() {
 // some code
},

// You can add more functions

}
Anouar Kacem
  • 635
  • 10
  • 24
  • module.exports = function (app) { verifyCustomerProfile = function(id){ console.log("I am here"); } } This is the sample of the function in the myScripts.js file. I am trying to use this function in my customerProfile.js model. – Adil Hassan Khanday Oct 16 '17 at 08:30