I can't understand why I'm getting this "Error: ENOENT" error. Here is my Meteor server method:
createImage: function(coords) {
console.log('createImage')
console.log(coords.area)
console.log(coords.x)
console.log(coords.y)
console.log(coords.x2)
console.log(coords.y2)
console.log(coords.w)
console.log(coords.h)
var gd = Meteor.npmRequire('node-gd');
var path = Meteor.npmRequire('path');
var fs = Meteor.npmRequire('fs');
var source = 'forrest.png';
var target = 'compimages';
if (path.exists(target)) fs.unlink(target);
gd.openPng(source, function(png, path) {
if(png) {
console.log(png)
console.log(path)
}
}
);
}
Here is the output I get from it on the terminal:
=> Meteor server restarted
I20140827-15:30:18.451(-7)? createImage
I20140827-15:30:18.455(-7)? 27888
I20140827-15:30:18.456(-7)? 242
I20140827-15:30:18.459(-7)? 164
I20140827-15:30:18.459(-7)? 410
I20140827-15:30:18.459(-7)? 330
I20140827-15:30:18.459(-7)? 168
I20140827-15:30:18.460(-7)? 166
W20140827-15:30:18.527(-7)? (STDERR) path.exists is now called `fs.exists`.
I20140827-15:30:18.547(-7)? { [Error: ENOENT, open 'forrest.png'] errno: 34, code: 'ENOENT', path: 'forrest.png' }
I20140827-15:30:18.548(-7)? undefined
These are the directories within ~/myapp/server/
me@ubuntu:~/myapp/server$ ls
compimages forrest.png privateimages server.js user-setup.js
I want to access forrest.png and use node-gd to cut a section of it out based on the coords passed in.
As far as I understand it this error means that there is a directory missing. The png file I'm trying to access is in the same directory as the .js file calling it (they are both in ~/myapp/server/ so to me it doesn't look like that's the problem. The only thing I can see is that the path is undefined. I've got that installed though:
me@ubuntu:~/myapp/packages/npm/npm/node_modules$ ls
node-gd path
Can anyone see what's going on with this? I'm using Meteor 0.9.0
If you console.log(process.cwd())
in your server code you will notice that the current working directory of your Meteor app is project/.meteor/local/build/programs/server
however your code assumes that the CWD is project/server
.
What you can do is prefixing your paths with the project root server folder which is obtained by going 5 level ups in the filesystem hierarchy.
var projectRootServer="../../../../../server";
var source=projectRootServer+"forrest.png";
This is not very elegant but it works.
Unrelated but it seems that path.exists
has been deprecated in favor of fs.exists
, you should fix this too.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments