Question

I'm using this module for my app on Openshift but when it needs to execute the function that checks if a file exists in the Data folder appers an error:

DEBUG: /var/lib/openshift/02A50df2XXYD46273d00FFG8/app-root/runtime/repo/server.js:164
        fs.exists('$OPENSHIFT_HOMEDIR/app-root/data/' + user_ip, function(exis
           ^

DEBUG: TypeError: Object #<Object> has no method 'exists'

I have the require fs in the server code and it's in dependencies at package.json

EDIT: Solved

Using require('path') and path.exists() it works well.

Was it helpful?

Solution

fs.exists() has been deprecated. Instead use path.exists(). For more information on path see node core path module.

OTHER TIPS

Advice:
According to the API Docs http://nodejs.org/api/fs.html#fs_fs_exists_path_callback

fs.exists() is an anachronism and exists only for historical reasons. There should almost never be a reason to use it in your own code.

In particular, checking if a file exists before opening it is an anti-pattern that leaves you vulnerable to race conditions: another process may remove the file between the calls to fs.exists() and fs.open(). Just open the file and handle the error when it's not there.

As for your issue: Are you able to make other fs calls?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top