NodeJS fs模块在Openshift中不起作用

时间:2022-11-15 03:03:37

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:

我在Openshift上使用此模块作为我的应用程序但是当它需要执行检查Data文件夹中是否存在文件的函数时会出现错误:

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

我在服务器代码中有需要的fs,它在package.json中的依赖项中

EDIT: Solved

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

使用require('path')和path.exists()可以很好地工作。

2 个解决方案

#1


1  

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

fs.exists()已被弃用。而是使用path.exists()。有关路径的更多信息,请参阅节点核心路径模块。

#2


0  

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

建议:根据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.

fs.exists()是一种时代错误,只是出于历史原因而存在。几乎没有理由在你自己的代码中使用它。

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.

特别是,在打开文件之前检查文件是否存在是一种反模式,使您容易受到竞争条件的影响:另一个进程可能会在调用fs.exists()和fs.open()之间删除该文件。只需打开文件并在错误处理时处理错误。

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

至于你的问题:你能进行其他fs通话吗?

#1


1  

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

fs.exists()已被弃用。而是使用path.exists()。有关路径的更多信息,请参阅节点核心路径模块。

#2


0  

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

建议:根据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.

fs.exists()是一种时代错误,只是出于历史原因而存在。几乎没有理由在你自己的代码中使用它。

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.

特别是,在打开文件之前检查文件是否存在是一种反模式,使您容易受到竞争条件的影响:另一个进程可能会在调用fs.exists()和fs.open()之间删除该文件。只需打开文件并在错误处理时处理错误。

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

至于你的问题:你能进行其他fs通话吗?