Load fmod studio library in node.js

Hi. I want to run examples from Javascript API in node.js, adapting them (the js examples) to run standalone in node.js without html, but I´m having errors when loading fmodstudio.js library using ‘require’.

I have in my script the standar setup for javascript as defined in documentation :

var FMOD = {}; // FMOD global object
FMOD[‘preRun’] = prerun;
FMOD[‘onRuntimeInitialized’] = main;
FMOD[‘TOTAL_MEMORY’] = 6410241024;
FMODModule(FMOD); // Calling the constructor function with our object

And I´m trying to load fmodstudio.js library with ‘require’ this way, but it doesn´t work:

var fmodstudiojs = require(’./fmodstudio.js’);

Any suggestions please in how to load it in my .js and acces it?

Thanks.

What errors are you getting?

1 Like

I successfully was able to load the fmodstudio.js library qith require:

  1. Inserting this in the fmodstudio.js file:

    module.exports.FMODModule = FMODModule;

  2. Calling this way the constructor function from the js example file:

fmodstudio1js.FMODModule(FMOD); // Calling the constructor function with our object

But now I´m having some errors because obviously ‘document’ is not defined in nodejs, because it is on the DOM in the frontend side:

if(typeof module!==“undefined”){module[“exports”]=Module}process[“on”](“uncaughtException”,(function(ex){if(!(ex instanceof ExitStatus)){throw ex}}));
^

ReferenceError: document is not defined
at prerun (D:\LMS_PROJ\NODE\FMOD\api\studio\examples\simple_event.js:87:9)
at callRuntimeCallbacks (D:\LMS_PROJ\NODE\FMOD\api\studio\examples\fmodstudio1.js:430:64)
at preRun (D:\LMS_PROJ\NODE\FMOD\api\studio\examples\fmodstudio1.js:444:71)
at run (D:\LMS_PROJ\NODE\FMOD\api\studio\examples\fmodstudio1.js:2195:2041)
at Object.FMODModule (D:\LMS_PROJ\NODE\FMOD\api\studio\examples\fmodstudio1.js:2195:3772)
at Object. (D:\LMS_PROJ\NODE\FMOD\api\studio\examples\simple_event.js:33:15)
at Module._compile (module.js:643:30)
at Object.Module._extensions…js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)

You will need to remove anything DOM related, the examples are all designed to be used with HTML.

1 Like