Note that there are some explanatory texts on larger screens.

plurals
  1. POLoad "Vanilla" Javascript Libraries into Node.js
    text
    copied!<p>There are some third party Javascript libraries that have some functionality I would like to use in a Node.js server. (Specifically I want to use a QuadTree javascript library that I found.) But these libraries are just straightforward <code>.js</code> files and not "Node.js libraries". </p> <p>As such, these libraries don't follow the <code>exports.var_name</code> syntax that Node.js expects for its modules. As far as I understand that means when you do <code>module = require('module_name');</code> or <code>module = require('./path/to/file.js');</code> you'll end up with a module with no publicly accessible functions, etc.</p> <p>My question then is "How do I load an arbitrary javascript file into Node.js such that I can utilize its functionality without having to rewrite it so that it does do <code>exports</code>?"</p> <p>I'm very new to Node.js so please let me know if there is some glaring hole in my understanding of how it works.</p> <hr/> <p><strong>EDIT</strong>: Researching into things more and I now see that the module loading pattern that Node.js uses is actually part of a recently developed standard for loading Javascript libraries called <a href="http://wiki.commonjs.org/wiki/Modules/1.1" rel="noreferrer">CommonJS</a>. It says this right on the <a href="http://nodejs.org/docs/v0.4.1/api/modules.html" rel="noreferrer">module doc page for Node.js</a>, but I missed that until now.</p> <p>It may end up being that the answer to my question is "wait until your library's authors get around to writing a CommonJS interface or do it your damn self."</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload