Using third-party JavaScript file in Node.js

I have a JavaScript file which is not written for Node.js. It is actually written by me, but this question may be more understandable if you think of it as a third-party library.

Normally, a Node.js module only exposes the module.exports object to external code. This requires the file to be written with Node.js in mind.

However, the file isn't written for Node.js, yet I want to include it into a Node.js module. I can't edit this file, since it will be used later, independently of Node.js.

I imagine I could pull it off by reading the file and calling eval on the contents, but is there a better way?

TL;DR

How can I include a .js file into a Node.js module, without rewriting it to use Node.js-specific code like exports?

P.S. The reason I want to use it in Node.js is for a few tests before it's deployed elsewhere.

It depends on how the code is written on that file. If the file contains a class or a single object then you can do this:

(function(global) {

    function MyClass() {


    }

    MyClass.prototype = {
            ...
    };

    if( typeof module !== "undefined" && module.exports ) {
        module.exports = MyClass;
    }
    else if ( global ) {
        global.MyClass = MyClass;
    }

})(this);

You can modify the global assignment to be a deeper namespace instead if required.