For example, I have profile.js
var EventEmitter = require("events").EventEmitter;
var https = require("https");
var http = require("http");
var util = require("util");
function Profile(username) {
// function code here
}
util.inherits( Profile, EventEmitter );
module.exports = Profile;
var Profile = require("./profile.js");
var studentProfile = new Profile("chalkers");
/**
* When the JSON body is fully recieved the
* the "end" event is triggered and the full body
* is given to the handler or callback
**/
studentProfile.on("end", console.dir);
/**
* If a parsing, network or HTTP error occurs an
* error object is passed in to the handler or callback
**/
studentProfile.on("error", console.error);
The require(...)
function returns the module.exports
value from the "required" module, and in the case its the Profile
function.