Meteor: Error: ENOENT when trying to access an image using node-gd

user1532669

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

saimeunt

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

ENOENT Error when deployed to meteor server

From Dev

ENOENT Error when deployed to meteor server

From Dev

403 Error When Trying To Access an Image URL

From Dev

Node error: connect ETIMEDOUT when trying to access route /setup

From Dev

ENOENT error when using fs.writeFile

From Dev

Error creating image with GD

From Dev

ENOENT error when trying to install Yeoman from npm

From Dev

npm throws ENOENT error when trying to install module

From Dev

node js ENOENT error

From Dev

Error when trying to save image in NSUserDefaults using Swift

From Dev

Error: ENOENT when renaming file in node/express app

From Dev

"Error: spawn mongoexport ENOENT" when running dockerized node app

From Dev

Node.js: Error: spawn ENOENT while using GM module

From Java

Segmentation Fault when trying to access pointer to Node

From Dev

Trying to Convert Image to Fixed Palette in PHP/GD

From Dev

Trying to Convert Image to Fixed Palette in PHP/GD

From Dev

Node js Error: spawn ENOENT

From Dev

Mailchimp Error: -100 when using node-mailchimp API in a Meteor app

From Dev

Error trying to insert image to BLOB type in Oracle database using node-oracledb

From Dev

syntax error when trying to join in Access

From Dev

Error when trying to access a pixel value in OpenCV

From Dev

Error when trying to access to a function in my service

From Dev

Error when trying to access variable inside a for loop

From Dev

Error when trying to save a captured image in swift

From Dev

Getting error when trying to resize an inserted image

From Dev

Error trying to upload an image when there is none on the db

From Dev

Error when trying to save a captured image in swift

From Dev

Error when using iron:router with Meteor 0.9.3.1

From Dev

Meteor error using npm package when deployed

Related Related

  1. 1

    ENOENT Error when deployed to meteor server

  2. 2

    ENOENT Error when deployed to meteor server

  3. 3

    403 Error When Trying To Access an Image URL

  4. 4

    Node error: connect ETIMEDOUT when trying to access route /setup

  5. 5

    ENOENT error when using fs.writeFile

  6. 6

    Error creating image with GD

  7. 7

    ENOENT error when trying to install Yeoman from npm

  8. 8

    npm throws ENOENT error when trying to install module

  9. 9

    node js ENOENT error

  10. 10

    Error when trying to save image in NSUserDefaults using Swift

  11. 11

    Error: ENOENT when renaming file in node/express app

  12. 12

    "Error: spawn mongoexport ENOENT" when running dockerized node app

  13. 13

    Node.js: Error: spawn ENOENT while using GM module

  14. 14

    Segmentation Fault when trying to access pointer to Node

  15. 15

    Trying to Convert Image to Fixed Palette in PHP/GD

  16. 16

    Trying to Convert Image to Fixed Palette in PHP/GD

  17. 17

    Node js Error: spawn ENOENT

  18. 18

    Mailchimp Error: -100 when using node-mailchimp API in a Meteor app

  19. 19

    Error trying to insert image to BLOB type in Oracle database using node-oracledb

  20. 20

    syntax error when trying to join in Access

  21. 21

    Error when trying to access a pixel value in OpenCV

  22. 22

    Error when trying to access to a function in my service

  23. 23

    Error when trying to access variable inside a for loop

  24. 24

    Error when trying to save a captured image in swift

  25. 25

    Getting error when trying to resize an inserted image

  26. 26

    Error trying to upload an image when there is none on the db

  27. 27

    Error when trying to save a captured image in swift

  28. 28

    Error when using iron:router with Meteor 0.9.3.1

  29. 29

    Meteor error using npm package when deployed

HotTag

Archive