Skip to content

Instantly share code, notes, and snippets.

@janjongboom
Created February 22, 2012 13:52
Show Gist options
  • Save janjongboom/1885247 to your computer and use it in GitHub Desktop.
Save janjongboom/1885247 to your computer and use it in GitHub Desktop.
function MyObject () {
// do stuff
}
// now to export this as a nodejs module do
module.exports = MyObject;
// =====
// in another file (in the same folder) you can now do
var MyObject = require("./MyObject");
// use it just like before
var obj = new MyObject();
@mrjcleaver
Copy link

In Summary, here's the changes I needed to make:

  1. At the top of the class TimeEntry.js, added a require line for the dependency:

var FreshBooks_Element = require('./Element');

  1. After the declaration of the function constructor in TimeEntry.js:
    function FreshBooks_TimeEntry()
    {
    this.elementName = "time_entry";
    ...
    }
    Added, per http://nodejs.org/api/modules.html#module.exports and http://stackoverflow.com/questions/8296379/create-a-class-in-nodejs:
    module.exports = FreshBooks_TimeEntry;

  2. After the declaration of the function constructor in Element.js:

function FreshBooks_Element()
{
...
}

Added:
module.exports = FreshBooks_Element;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment