Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Node.js fs.open带有选项';a';生成EACCES错误_Javascript_Linux_Node.js_Createfile_Fs - Fatal编程技术网

Javascript Node.js fs.open带有选项';a';生成EACCES错误

Javascript Node.js fs.open带有选项';a';生成EACCES错误,javascript,linux,node.js,createfile,fs,Javascript,Linux,Node.js,Createfile,Fs,我正在尝试使用node.js的fs模块根据POST请求创建xml文件 filePath = path.normalize(path.join(profilesDirPath, name + xmlExt)); fs.exists(filePath, function(exists) { if (exists) { callback({ code: h.httpStatus.CONFLICT,

我正在尝试使用node.js的fs模块根据POST请求创建xml文件

    filePath = path.normalize(path.join(profilesDirPath, name + xmlExt));

    fs.exists(filePath, function(exists) {
        if (exists) {
            callback({
                code: h.httpStatus.CONFLICT,
                resp: 'audio profile group with such name exists'
            });
            return;
        }

        fs.open(filePath, 'a', function(error) {
            if (error) {
                callback({
                    code: h.httpStatus.INTERNAL_SERVER_ERROR,
                    resp: error
                });
                return;
            }

            callback(null);
        });
    });
这会导致错误:

{
    "errno": 3,
    "code": "EACCES",
    "path": "/mount/fs/folder/newGroup.xml"
}
节点进程在Linux和文件夹上运行,我尝试在同一台机器上创建这样的文件

更重要的是,我对mkdir没有任何问题


我理解,这与权限有关,但我无法理解为什么它与创建文件夹不同,以及如何解决这一问题。

您应该做的第一件事是确定node.js应用程序运行的用户/组组合

与linux/unix中的任何进程一样,node.js在运行时继承用户和组成员的文件系统权限

您可以通过使用
lsof
ps
检查正在运行的进程来实现这一点

简而言之(显示正在运行的节点应用程序用户):

您应该确定的第二件事是,所讨论的文件(即/mount/fs/folder/newGroup.xml)是否具有“写入/附加”权限,您当前正在将其指定为
fs.open()
模式

您可以确定文件的权限(我假设该文件将是只读文件共享,因为
/mount
的装入点指示可能的只读文件系统,例如DVD/CD驱动器上的文件系统),如下所示:


ls-lah/mount/fs/folder/newGroup.xml

jaz-,感谢您的详细回答!事实上,读了你的答案,我意识到,我犯了一个惊人的愚蠢错误。我没有检查文件系统的状态。而且它是只读模式。不用担心,很高兴它有帮助。
ps xaf | grep node | awk '{ system("lsof | grep " $1) }' | awk '{ print $3 }'