How to install fabric.js on node.js
I am trying to install fabric.js on synology nas which has node.js installed. I installed first using an antenna mounting cloth. This downloaded and copied the files, but didn't install them in node_modules, so the cloth module doesn't work. Then I tried to install using npm install fabric but I got node_gyp errors not finding the make.env file. I'm new to node and Linux, so forgive the possibly stupid question.
thank
source to share
I didn't work on synology server specifically, but I remember running some random errors when setting up my last server. I could be wrong, but I believe your installation files in the node_modules folder are fine.
A few thoughts:
dependencies
FabircJS requires the canvas to be set as well. This can be done with npm vianpm install -g canvas
Installation volume
npm packages can be installed locally (available from direct location / folder) or globally. I personally prefer a global install, so it's always readily available - I don't know about these shortcomings personally, but it could be both. To install globally, you simply add a flag -g
to your npm install commands. I believe that if you installed the package locally, the second time with a global flag, the first installation will be overwritten.
Link: http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation
Test setup
Check if your installation works.
- On Linux command line, first change directory to node_modules folder - for my server this is
cd /usr/lib/node_modules/
. - Start node by typing
node
- Check if the canvas is installed and working by typing
typeof require('canvas');
. If the canvas is working correctly, you should see it returned'function'
. - If canvas is working then check if FabricJS is working by typing
typeof require('fabric');
. If everything works well, you will see'object'
and FabricJS is installed and working well.
Link: http://promincproductions.com/blog/installing-fabricjs-for-nodejs-on-linux/
Require at node Server
Now that you know it is installed and working correctly, the next step is to get it to work in your scenarios. The only real trick here is to require modules at the top of your script.
var fabric = require('fabric').fabric;
This should work fine now, but if it doesn't, you may need to specify your request by path, as opposed to the npm package name as you did above. I think the path is necessary unless you have FabricJS installed globally. It will look something like this:
var fabric = require('/usr/lib/node_modules/fabric').fabric;
Link: http://www.bennadel.com/blog/2169-where-does-node-js-and-require-look-for-modules.htm
source to share