# Load fmod studio library in node.js

**URL:** https://qa.fmod.com/t/load-fmod-studio-library-in-node-js/13737
**Category:** FMOD Studio
**Created:** [March 4, 2018, 8:12pm UTC](https://qa.fmod.com/t/load-fmod-studio-library-in-node-js/13737 "2018-03-04T20:12:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![joprmz](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@joprmz](https://qa.fmod.com/u/joprmz)
#### Post date: [March 4, 2018, 8:12pm UTC](https://qa.fmod.com/t/load-fmod-studio-library-in-node-js/13737/1 "2018-03-04T20:12:22Z")

</div>

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’] = 64_1024_1024;  
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.

---

<div class="post-metadata">

### Author: ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)
#### Post date: [March 7, 2018, 12:38am UTC](https://qa.fmod.com/t/load-fmod-studio-library-in-node-js/13737/2 "2018-03-07T00:38:07Z")

</div>

> [@](#):
>
> 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’] = 64_1024_1024;  
> 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?

---

<div class="post-metadata">

### Author: ![joprmz](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@joprmz](https://qa.fmod.com/u/joprmz)
#### Post date: [March 10, 2018, 12:40pm UTC](https://qa.fmod.com/t/load-fmod-studio-library-in-node-js/13737/3 "2018-03-10T12:40:38Z")

</div>

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

1. Inserting this in the fmodstudio.js file:

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)

---

<div class="post-metadata">

### Author: ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)
#### Post date: [March 13, 2018, 11:12pm UTC](https://qa.fmod.com/t/load-fmod-studio-library-in-node-js/13737/4 "2018-03-13T23:12:32Z")

</div>

> [@](#):
>
> I successfully was able to load the fmodstudio.js library qith require:
> 
> 1. Inserting this in the fmodstudio.js file:
> 
> 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.
