简体   繁体   中英

Trouble calling a function from a different file: “updateDB.inputFormToDB is not a function”

Github source for reference

Files where issue exists: updateDB.js , quickstart.js

Inside quickstart.js I have set a variable updateDB on line 2:

var updateDB = require('./updateDB.js');

which I believe refers to my updateDB.js file (which is currently living in the same folder).

However later in the file when I try to call a function from updateDB.js on line 118:

    updateDB.inputFormToDB(rows);

I get the error " updateDB.inputFormToDB is not a function ".

Inside updateDB.js I have things set up as follows:

var updateDB= function() {
 some function    
 var inputFormToDB = function(parameter) {
     function code
 }
 some function
 some function
};
module.exports = updateDB;

Am I missing something to call my function from inside quickstart.js ??? I feel like I'm making some small mistake somewhere.

The problem is in

var updateDB = function() {...}

should be

var updateDB = {...}

like a Object.

eg

var updateDB = {
  inputFormToDB: function() {...}
}

or

var updateDB = function() {
  var x = ...

  function inputFormToDB() {...}

  return {
    inputFormToDB: inputFormToDB
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM