Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
37
rated 0 times [  43] [ 6]  / answers: 1 / hits: 20819  / 11 Years ago, fri, january 3, 2014, 12:00:00

I've put together a little code in one file, which is below:



var exports = Symphonize;

function Symphonize(generation_specification) {
this.generate_spec = function(){
return generation_specification;
}
}


When I start another JavaScript file in the same project and require the code like so:



var symphonize = require('../bin/symphonize');
var Symp = new symphonize({test:test1});


It throws the error:




/Users/adron/Codez/symphonize/tests/symphonize.js:8



var Symp = new symphonize({test:test1});



          ^ TypeError: object is not a function at Object.<anonymous>



Is there another way I should be constructing this? I just want the symphonize code to require a simple object (an object of configuration that will be JSON) before any functions on that code are called.


More From » node.js

 Answers
4

When setting the exports something you must do module.exports = Something. You should do something like :



module.exports = Symphonize;


If you had Symphonize as a property on the exports module.exports is not needed



exports.Symphonize = Symphonize;


Use it in a file.



var Symphonize = require('../bin/symphonize').Symphonize





Also var exports is kind of ambiguous statement in Node.


[#73389] Thursday, January 2, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadyngraysons

Total Points: 455
Total Questions: 109
Total Answers: 98

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
jadyngraysons questions
Thu, Apr 23, 20, 00:00, 4 Years ago
Sat, Jan 18, 20, 00:00, 4 Years ago
Tue, Dec 31, 19, 00:00, 4 Years ago
;