# Using PM2 on MacOS: fs-ops-dir node (node-red-contrib-fs-ops) permission issue

**URL:** <https://discourse.nodered.org/t/using-pm2-on-macos-fs-ops-dir-node-node-red-contrib-fs-ops-permission-issue/47405>\
**Category:** General\
**Created:** [20 June 2021 17:53 UTC](https://discourse.nodered.org/t/using-pm2-on-macos-fs-ops-dir-node-node-red-contrib-fs-ops-permission-issue/47405 "2021-06-20T17:53:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rakgupta](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rakgupta/32/42535_2.png) [@rakgupta](https://discourse.nodered.org/u/rakgupta)\
**Post date:** [20 June 2021 17:53 UTC](https://discourse.nodered.org/t/using-pm2-on-macos-fs-ops-dir-node-node-red-contrib-fs-ops-permission-issue/47405/1 "2021-06-20T17:53:30Z")

</div>

**UPDATE** : This is part of node-red-contrib-fs-ops

Hello - I am running into what I think is a permissions problem with the fs-ops-dir node (directory node) when using PM2. I have a flow that scans a folder, identifies the latest file and ftp's it a NAS folder.

In the launchd script for PM2, the user parameter is correct (my username) but when the node tries to access the folder, it returns an error (Error: EPERM: operation not permitted, scandir). If I stop the Node-RED process from PM2 and launch it directly from the terminal, it works correctly.

Any idea what I can do to fix this? Thanks for your help.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [21 June 2021 08:48 UTC](https://discourse.nodered.org/t/using-pm2-on-macos-fs-ops-dir-node-node-red-contrib-fs-ops-permission-issue/47405/2 "2021-06-21T08:48:29Z")

</div>

What version of macOS?  
What version of NR and node.js? (you can get this from the startup log)  
Is there anythng else in the log with that message?  
have you tried a google search `EPERM: operation not permitted, scandir macos`?  
What happens if you just send the file to user directory on the Mac?

---

<div class="post-metadata">

**Author:** ![rakgupta](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rakgupta/32/42535_2.png) [@rakgupta](https://discourse.nodered.org/u/rakgupta)\
**Post date:** [21 June 2021 11:33 UTC](https://discourse.nodered.org/t/using-pm2-on-macos-fs-ops-dir-node-node-red-contrib-fs-ops-permission-issue/47405/3 "2021-06-21T11:33:34Z")

</div>

> [@zenofmud](#):
>
> What version of macOS?

MacOS Catalina

> [@zenofmud](#):
>
> What version of NR and node.js? (you can get this from the startup log)

Node - 14.15.4  
Node-RED - 1.2.6

> [@zenofmud](#):
>
> Is there anythng else in the log with that message?

```auto
[Error: EPERM: operation not permitted, open '/Users/rakeshgupta/Documents/MySQLBackup/2021-06-20_DB_Export.sql'] {
  errno: -1,
  code: 'EPERM',
  syscall: 'open',
  path: '/Users/rakeshgupta/Documents/MySQLBackup/2021-06-20_DB_Export.sql'
}
(node:52552) Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency

```

> [@zenofmud](#):
>
> have you tried a google search `EPERM: operation not permitted, scandir macos` ?

Yes

> [@zenofmud](#):
>
> What happens if you just send the file to user directory on the Mac?

I'm not sure what you mean - the file is already in the user directory. As I said in the original message, if I run NR directly (not via PM2), it works correctly.  
EDIT: Did you mean instead of ftp? The file is on the same Mac that NR is running on. It is a mySQL export (created with mySQLdump), and NR is ftp'ing the file f **rom the Mac** to a **NAS**.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 June 2021 11:43 UTC](https://discourse.nodered.org/t/using-pm2-on-macos-fs-ops-dir-node-node-red-contrib-fs-ops-permission-issue/47405/4 "2021-06-21T11:43:09Z")

</div>

> [@rakgupta](#):
>
> if I run NR directly (not via PM2), it works correctly.

This suggests the account running PM2 does not have access to `/Users/rakeshgupta/Documents`

I am not an apple/mac user so have no idea how PM2 is ran but I suspect it is a system account or service account running PM2 that does not (and rightly so) have access to a users docs.

Try either

- moving the file to a location all users can access  
OR
- adjusting permissions on the folder `/Users/rakeshgupta/Documents`  
OR
- running PM2 as your user (rakeshgupta)

I would personally recommend option 1 (for security reasons)

---

<div class="post-metadata">

**Author:** ![rakgupta](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rakgupta/32/42535_2.png) [@rakgupta](https://discourse.nodered.org/u/rakgupta)\
**Post date:** [21 June 2021 11:54 UTC](https://discourse.nodered.org/t/using-pm2-on-macos-fs-ops-dir-node-node-red-contrib-fs-ops-permission-issue/47405/5 "2021-06-21T11:54:53Z")

</div>

> [@Steve-Mcl](#):
>
> adjusting permissions on the folder `/Users/rakeshgupta/Documents`

I had tried giving all users access to that folder (just to try it!!) and it did not seem to work

> [@Steve-Mcl](#):
>
> running PM2 as your user (rakeshgupta)

PM2 creates a script (launchctl) that is put in the correct user directory, so I thought it was running under that username. I guess not - and that's why I was confused.

> [@Steve-Mcl](#):
>
> moving the file to a location all users can access

Yeah - I think I may have to go that route. Just need to figure out what that would be on the Mac.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![rakgupta](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rakgupta/32/42535_2.png) [@rakgupta](https://discourse.nodered.org/u/rakgupta)\
**Post date:** [21 June 2021 12:12 UTC](https://discourse.nodered.org/t/using-pm2-on-macos-fs-ops-dir-node-node-red-contrib-fs-ops-permission-issue/47405/6 "2021-06-21T12:12:10Z")

</div>

> [@Steve-Mcl](#):
>
> moving the file to a location all users can access

Looks like this will work - I moved the file into Users/rakeshgupta/Public/ folder and now when I run my test flow, I don't get the permissions error.

Thanks a ton for your help

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [21 June 2021 12:15 UTC](https://discourse.nodered.org/t/using-pm2-on-macos-fs-ops-dir-node-node-red-contrib-fs-ops-permission-issue/47405/7 "2021-06-21T12:15:59Z")

</div>

My guess is ths is a result of **System Integrity Protection (SIP)** (which you would have discovered if you had done a google search using the terms I suggested). [Here](https://apple.stackexchange.com/questions/193368/what-is-the-rootless-feature-in-el-capitan-really) is an explaination of what it is.

Try puting the original file in **`/usr/local/bin`**

---

<div class="post-metadata">

**Author:** ![rakgupta](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rakgupta/32/42535_2.png) [@rakgupta](https://discourse.nodered.org/u/rakgupta)\
**Post date:** [21 June 2021 12:21 UTC](https://discourse.nodered.org/t/using-pm2-on-macos-fs-ops-dir-node-node-red-contrib-fs-ops-permission-issue/47405/8 "2021-06-21T12:21:23Z")

</div>

> [@zenofmud](#):
>
> My guess is ths is a result of **System Integrity Protection (SIP)** (which you would have discovered if you had done a google search using the terms I suggested).

Thanks - that's what I had found but it seemed to refer more to the OS folders. Since I was running PM2 (I thought) as the user, I wasn't sure WHY it would not have access to the user folders.

> [@zenofmud](#):
>
> Try puting the original file in **`/usr/local/bin`**

I had forgotten that there is a "public" folder in each user's directory on the Mac. @Steve-Mcl suggestion jogged that memory and is probably a better solution than using the /usr/local/bin directory (it's messy enough as it is!)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 July 2021 12:22 UTC](https://discourse.nodered.org/t/using-pm2-on-macos-fs-ops-dir-node-node-red-contrib-fs-ops-permission-issue/47405/9 "2021-07-05T12:22:22Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
