문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top