Is it possible to transform a regular Javascript library into a NodeJS library?

I've been working with a Javascript library, namely, canvas-lib and I'm using Node.JS/Socket.io on the server side so I can pass events between clients.

I'm using an architecture in which only 1 client at a time is allowed control over the canvas since I'm making kind of a "scratch" game which is controlled by a mobile device and displayed on an second (bigger) screen.

You can see a diagram of the architecture here.

The thing is, currently the canvas interaction is done on the client side on a script for that effect which causes the some problems:

  • There's no way of scaling the canvas
  • There's not a unified time limit counter
  • I have to manually load the page on the external screen

My objectives are:

  • To have the server pass the time to both devices (or screens)
  • To have the canvas loaded on the mobile device and scaled to the external screen (on new connection, and done automatically once the mobile device is connected, or out of the queue and into current active)

In order to achieve this, I believe I must get the canvas-lib to work on node, so how can I achieve this since the lib is not ready for that yet? How can I turn a regular library into a Node library?

Well,

if you're developing a library which does stuff specifically for browsers I can't see any point in making a Node package for it.

But anyway, please take a look at the Node Package Manager (NPM for short), it'll help you whenever you need to develop some Node library.

Some of the things I've done to make Fabric.js node-compatible:

  • Use node-canvas which provides canvas API in node environment.
  • Provide (or prevent) access to any DOM objects that library might be using. See jsdom.
  • Remove calls to proprietary (browser-only) API. See non-standard features.
  • Adapt library's test suite to run under node (if it doesn't yet). See mocha or qunit.
  • Run test suite and make sure everything still functions as expected.
  • (optionally) Create NPM package for convenience.

Or you can just use the library that already provides support for node ;)