Model.js file has the following entry
exports.update = function(tag,view,date){
{
.....
....
}
and calling the function like
update('test','1213','11/10/2014')
it throws the following error,
update('test','1213','11/10/2014')
^
ReferenceError: update is not defined
I can call the update module from the different file, without any error something like this
var model = require('./Model');
model.update('test','1213','2001/1/23')
The question is how can invoke the Update method from the same js (Model.js )file
Model.js file has the following entry
exports.update = function(tag,view,date){
{
.....
....
}
and calling the function like
update('test','1213','11/10/2014')
it throws the following error,
update('test','1213','11/10/2014')
^
ReferenceError: update is not defined
I can call the update module from the different file, without any error something like this
var model = require('./Model');
model.update('test','1213','2001/1/23')
The question is how can invoke the Update method from the same js (Model.js )file
Share Improve this question asked Oct 30, 2014 at 6:40 anishanish 7,44814 gold badges84 silver badges153 bronze badges2 Answers
Reset to default 4In model.js
exports.update = function update(tag, view, date) { ... }
exports.update('red', 'colors', new Date())
Also consider declaring a local variable if you call the method often (like in a loop)
var update = exports.update = function update(tag, view, date) { ... }
update('red', 'colors', new Date())
Inside foo.js
var update = require('./model').update
update('yellow', 'colors', new Date())
Is not clear from the question itself what the update method does and on which data, so the answer may be tweaked if you provide real code.
You have to first define the function, and then export the function like this-
var update=function(tag,view,date){
......
}
module.exports={
update:update
}
By doing this you can access the 'update()' function from inside as well as outside of the file.