Error: ENOENT: no such file or directory, open 'privkey.pem'

I installed the Node-Red docker (version 1.3.5) into QNAP NAS container station successfully, but have not managed to make the https function work yet. I mapped the "/data" folder of the docker to "/share/Storage/NASSoftwares/node-red", so that I can edit "settings.js".

In "settings.js", I uncommented the following lines:

adminAuth: {
    type: "credentials",
    users: [{
        username: "NOTREAL",
        password: "$NOTREALNOTREALNOTREALNOTREALNOTREALNOTREAL",
        permissions: "*"
    }]
},

https: function() {
     // This function should return the options object, or a Promise
     // that resolves to the options object
     return {
         key: require("fs").readFileSync('privkey.pem'),
         cert: require("fs").readFileSync('fullchain.pem')
     }
 },

Then when I tried to start the docker, the docker gave me the following info:

Error: ENOENT: no such file or directory, open 'privkey.pem'                                                                                                                                                                      
    at Object.openSync (fs.js:443:3)                                                                                                                                                                                              
    at Object.readFileSync (fs.js:343:35)                                                                                                                                                                                         
    at https (/data/settings.js:160:29)                                                                                                                                                                                           
    at Object.<anonymous> (/usr/src/node-red/node_modules/node-red/red.js:203:20)                                                                                                                                                 
    at Module._compile (internal/modules/cjs/loader.js:778:30)                                                                                                                                                                    
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)                                                                                                                                                      
    at Module.load (internal/modules/cjs/loader.js:653:32)                                                                                                                                                                        
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)                                                                                                                                                                      
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)                                                                                                                                                               
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)                                                                                                                                                            
npm ERR! code ELIFECYCLE                                                                                                                                                                                                          
npm ERR! errno 1                                                                                                                                                                                                                  
npm ERR! node-red-docker@1.3.5 start: `node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS "--userDir" "/data"`                                                                                                                
npm ERR! Exit status 1                                                                                                                                                                                                            
npm ERR!                                                                                                                                                                                                                          
npm ERR! Failed at the node-red-docker@1.3.5 start script.                                                                                                                                                                        
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.                                                                                                                                
                                                                                                                                                                                                                                  
npm ERR! A complete log of this run can be found in:                                                                                                                                                                              
npm ERR!     /data/.npm/_logs/2021-06-25T10_57_20_767Z-debug.log

Only when I re-commented the cert and key out can the docker start again. I used the docker terminal to use "ls" to show all the files in the docker, only these two appeared:

node_modules  package.json

However, when I tried to access the same folder through samba or WINSCP, I could see a whole bunch of other stuff showing up as follows:

.config.nodes.json
.config.nodes.json.backup
.config.runtime.json
.config.users.json
.config.users.json.backup
.flows.json.backup
.npm
flows.json
fullchain.pem
lib
node_modules
node-red-contrib-home-assistant-websocket.json
package.json
package-lock.json
privkey.pem
settings.js
ssh

I assumed that it was a permissions problem, so I used WINSCP to modify my fullchain.pem and privkey.pem to share identical group, owner and other permissions settings with package.json (i.e. the file that did show up in the response of "ls" command in the docker), but nothing changed as the docker still showed the same error message. I have struggled with this for days, and researched all the relevant posts on the Internet, so if anyone can point me to the right direction, I would appreciate it so much.

Change privkey.pem to the full path to the file (from the point of view of the container) - so /data/privkey.pem.

Without the full path, node will treat it as a file relative to the working directory of the process. The Node-RED Docker image's working directory is not /data.

Yes! Adding "/data" definitely did the trick! Thank you for your quick reply!

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