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.
- In the Linux command line, first change your directory to the node_modules folder - for my server it is
cd /usr/lib/node_modules/
.
- Start node by typing
node
- Test if canvas is installed and working properly by typing
typeof require('canvas');
. If canvas is working correctly you should see 'function'
returned.
- 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