Node.js error after installing via dietpi-software

Hi, I am trying to install node.js and node-red to build my custom node.

But even at the beginning I am getting errors. After installing via dietpi-software, if I run npm doctor, I get the following errors:

npm WARN checkFilesPermission error getting info for /usr/bin/node_modules
npm WARN checkFilesPermission error getting info for /usr/bin/node_modules/.bin
Check                               Value   Recommendation/Notes
npm ping                            ok
npm -v                              not ok  Use npm v8.1.0
node -v                             ok      current: v16.11.1, recommended: v16.11.1
npm config get registry             ok      using default registry (https://registry.npmjs.org/)
which git                           ok      /usr/bin/git
Perms check on cached files         ok
Perms check on local node_modules   not ok  Check the permissions of files in /usr/bin/node_modules (should be owned by current user)
Perms check on global node_modules  ok
Perms check on local bin folder     not ok  Check the permissions of files in /usr/bin/node_modules/.bin
Perms check on global bin folder    ok
Verify cache contents               ok      verified 347 tarballs

npm ERR! Some problems found. See above for recommendations.

I have played with user permissions but no luck yet. I also tried using nvm as well.

Hi,

this might be expected as on DietPi we start NodeRed with a custom user directory /mnt/dietpi_userdata/node-red

This is the start command from the service definition

ExecStart=/mnt/dietpi_userdata/node-red/node_modules/.bin/node-red -u /mnt/dietpi_userdata/node-red

As well the service is started as own user nodered

I guess you would need to switch into user directory and execute it from there

cd /mnt/dietpi_userdata/node-red
sudo -u nodered npm doctor



root@DietPi4:/mnt/dietpi_userdata/node-red# sudo -u nodered npm doctor
Check                               Value  Recommendation/Notes
npm ping                            ok
npm -v                              ok     current: v8.1.0, latest: v8.1.0
node -v                             ok     current: v17.0.0, recommended: v17.0.0
npm config get registry             ok     using default registry (https://registry.npmjs.org/)
which git                           ok     /usr/bin/git
Perms check on cached files         ok
Perms check on local node_modules   ok
Perms check on global node_modules  ok
Perms check on local bin folder     ok
Perms check on global bin folder    ok
Verify cache contents               ok     verified 528 tarballs
root@DietPi4:/mnt/dietpi_userdata/node-red#

I see, thanks Joulinar . I am getting the same results now.

However, If I try to install any npm module, I am getting the following error:

Error: EACCES: permission denied, mkdir ‘/mnt/dietpi_userdata/node-red/node_modules/@abandonware

As far as I know, installing npm modules with sudo is not also suggested.

How should I proceed?

how does permissions looks like

ls -la /mnt/dietpi_userdata/node-red/node_modules/

I followed the steps mentioned https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally.

Now, it works all fine.

Means you changed default directory now? I guess we simply could have fixed file system permissions.

Sorry, I missed your post. The permissions are as follows:

drwxr-xr-x   4 nodered nodered   4096 Oct 20 13:42 node-red



I guess we simply could have fixed file system permissions.

In this discussion, they suggest not the play with user permissions. Also official node.js doc. suggest the same thing.

But do you suggest changing permissions?

Edit: Btw, that fix only applies to when we install nodes globally, not locally.

Could you suggest a permission fix, where I can install global and local nodes without root permission?

try to use sudo -u nodered as this will install packages as nodered user and should target directory /mnt/dietpi_userdata/node-red/node_modules/

Thanks Joulinar now, it loads to correct place.

However getting a new error as

[warn] [node-red-contrib-ble-sense/protocols] Error: EAFNOSUPPORT, Address family not supported by protocol

The examples I found are all related to dockers that made me confused. I am digging into this now.

Edit: My npm packages depends on @abandonware/noble.

Edit-2: Apparently, this was because the bluetooth was disabled :cry: , I enabled it and all fine now :sunglasses: .

Due to my questions, we kind of moved more on the topic, hence I am accepting Joulinar’s answer that fix the question in the title.

yes bluetooth is disabled by default and needs to be enabled manually :sunglasses: