node application getting \"Error: EACCES: permissi

2019-07-24 21:38发布

问题:

I am running node-red on my raspberry pi and am trying to get a node that I wrote myself working on it. The node works fine on my windows PC but I haven't been able to get it working on my pi yet.

My node uses mailin to setup an SMTP server but I don't think it's an issue with that package.

mailin is trying to create a temporary folder but it obviously doesn't have permissions. How do I give node the permissions it needs to be able to create this folder?

full error:

5 Apr 20:06:22 - [info] Starting flows
shell.js: internal error
Error: EACCES: permission denied, mkdir '.tmp'
at Error (native)
at Object.fs.mkdirSync (fs.js:794:18)
at mkdirSyncRecursive (/home/pi/.node-red/node_modules/node-red-contrib-mailin-smtp/node_modules/mailin/node_modules/shelljs/src/mkdir.js:11:8)
at /home/pi/.node-red/node_modules/node-red-contrib-mailin-smtp/node_modules/mailin/node_modules/shelljs/src/mkdir.js:63:7
at Array.forEach (native)
at Object._mkdir (/home/pi/.node-red/node_modules/node-red-contrib-mailin-smtp/node_modules/mailin/node_modules/shelljs/src/mkdir.js:48:8)
at Object.mkdir (/home/pi/.node-red/node_modules/node-red-contrib-mailin-smtp/node_modules/mailin/node_modules/shelljs/src/common.js:186:23)
at Mailin.start (/home/pi/.node-red/node_modules/node-red-contrib-mailin-smtp/node_modules/mailin/lib/mailin.js:73:15)
at new MailinSMTP (/home/pi/.node-red/node_modules/node-red-contrib-mailin-smtp/mailinSMTP.js:15:10)
at createNode (/usr/lib/node_modules/node-red/red/runtime/nodes/flows/Flow.js:276:18)
at Flow.start (/usr/lib/node_modules/node-red/red/runtime/nodes/flows/Flow.js:64:35)
at start (/usr/lib/node_modules/node-red/red/runtime/nodes/flows/index.js:264:29)
at tryCatchReject (/usr/lib/node_modules/node-red/node_modules/when/lib/makePromise.js:845:30)
at runContinuation1 (/usr/lib/node_modules/node-red/node_modules/when/lib/makePromise.js:804:4)
at Fulfilled.when (/usr/lib/node_modules/node-red/node_modules/when/lib/makePromise.js:592:4)
at Pending.run (/usr/lib/node_modules/node-red/node_modules/when/lib/makePromise.js:483:13)
nodered.service: main process exited, code=exited, status=1/FAILURE

Many Thanks

回答1:

The problem here was that mailin was trying to create a temp folder within the root folder for node which was not allowed. Looking at the code for mailin though I was able to pass a different folder to use for temporary files. I did this by adding a tmp property to the config object and set it to os.tempdir()/mailin