5

I am trying to install fabric.js on a synology nas which has node.js installed. I installed first using bower install fabric. That has downloaded and copied files but not installed them in node_modules so the fabric module does not work. I then tried installing using npm install fabric but I got node_gyp errors not finding a make.env file. I am new to node and Linux so forgive the possibly stupid question.

Thanks

Franck Dervaux
  • 121
  • 2
  • 12

1 Answers1

6

I haven't worked on a synology server specifically, but I recall running into some random errors when setting up my last server as well. I could be wrong, but I believe having your installation files in the node_modules folder is just fine.

A few thoughts:

Dependancies

FabircJS requires that canvas is installed as well. This can be done easily with npm via npm install -g canvas

Scope of Install

npm packages can be installed locally (accessed by a direct location/folder) or globally. I personally prefer global installs so it's always readily accessible - I'm not aware of any downsides to this personally, but there may be some. To install globally, you simply add the -g flag to your npm install commands. I believe if you installed a package locally, installing it a second time with the global flag will overwrite the first install.

Reference: http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation

Test Setup

Test if your install is working.

  1. In the Linux command line, first change your directory to the node_modules folder - for my server it is cd /usr/lib/node_modules/.
  2. Start node by typing node
  3. Test if canvas is installed and working properly by typing typeof require('canvas');. If canvas is working correctly you should see 'function' returned.
  4. If canvas is working, then test to see if FabricJS is working as well by typing typeof require('fabric');. If all is working well, then you'll see 'object' returned and FabricJS is installed and working well.

Reference: http://promincproductions.com/blog/installing-fabricjs-for-nodejs-on-linux/

Require in Node Server

Now that you know it is installed and working correctly, the next step is to make it work in your scripts. The only real trick here is to require the modules at the top of your script.

var fabric = require('fabric').fabric;

Now that should work just fine, but if it doesn't, you may have to specify your require via a path as opposed to the npm package name like was done above. I think the path is required if you FabricJS wasn't installed globally. This would look something more like:

var fabric = require('/usr/lib/node_modules/fabric').fabric;

Reference: http://www.bennadel.com/blog/2169-where-does-node-js-and-require-look-for-modules.htm

PromInc
  • 1,174
  • 7
  • 12
  • Thanks you very much for this step by step and very detailed answer. I soon realized the issue was probably due to many missing dependencies on the Synology machine, which is not designed as a development environment. I therefore installed Ubuntu on a spare machine and installed fabric and all its dependencies on it very easily. Up to me now to write amazing code that takes advantage of this amazing library. I will nevertheless follow your instructions and try complete installation on my synology nas. Thank you again. – Franck Dervaux Dec 18 '14 at 07:56