Pexeus / LTE-Car

43 stars 13 forks source link

/bin/sh: 1: node: not found in terminal when running node js on raspberry pi #17

Open mcelhinnysp opened 1 week ago

mcelhinnysp commented 1 week ago

Background

I have installed nodejs v14.21.3 using nvm onto a fresh 64 bit raspberry pi 4 model B. I have followed the readme instructions to the best of my experience, albeit very limited. I have installed pigpio and socat as covered in the github readme. After running npm install into the onboard folder, I run the program (elevated with sudo, see below). It connects, but when I click start from the webserver interface, the /bin/sh error appears. I have no experience in this area, any guidance would be appreciated.

All code has been run from Raspberry Pi terminal.

After running npm install, I tried running as called in the readme.

Non-Elevated Approach

This is based on code from the readme

test@raspberrypi:~/Documents/LTE car/LTE-Car-main/onboard $ node index.js
standby service ready [192.168.1.126]

[LTE-Car Error]: 2024-09-23 10:22:39 initCheckPermitted: 
+---------------------------------------------------------+
|Sorry, you don't have permission to run this program.    |
|Try running as root, e.g. precede the command with sudo. |
+---------------------------------------------------------+

[LTE-Car Error]: /home/test/Documents/LTE car/LTE-Car-main/onboard/node_modules/pigpio/pigpio.js:54
    pigpio.gpioInitialise();
           ^

Error: pigpio error -1 in gpioInitialise
    at initializePigpio (/home/test/Documents/LTE car/LTE-Car-main/onboard/node_modules/pigpio/pigpio.js:54:12)
    at new Gpio (/home/test/Documents/LTE car/LTE-Car-main/onboard/node_modules/pigpio/pigpio.js:158:5)
    at pin (/home/test/Documents/LTE car/LTE-Car-main/onboard/driver/control.js:53:12)
    at Object.<anonymous> (/home/test/Documents/LTE car/LTE-Car-main/onboard/driver/control.js:3:18)
    at Module._compile (internal/modules/cjs/loader.js:1114:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
    at Module.load (internal/modules/cjs/loader.js:979:32)
    at Function.Module._load (internal/modules/cjs/loader.js:819:12)
    at Module.require (internal/modules/cjs/loader.js:1003:19)
    at require (internal/modules/cjs/helpers.js:107:18)

Elevated Approach

Based on the guidance in the error, I tried running as with elevated access

Attempt without absolute node path

test@raspberrypi:~/Documents/LTE car/LTE-Car-main/onboard $ sudo node index.js sudo: node: command not found

The pi did not connect at all in this case

Attempt with absolute node path

Based on some interaction with ChatGPT, I tried the absolute node path

test@raspberrypi:~/Documents/LTE car/LTE-Car-main/onboard $ sudo /home/test/.nvm/versions/node/v14.21.3/bin/node index.js standby service ready [192.168.1.126] [LTE-Car Error]: /bin/sh: 1: node: not found The absolute path was obtained by running:

test@raspberrypi:~/Documents/LTE car/LTE-Car-main/onboard $ which node /home/test/.nvm/versions/node/v14.21.3/bin/node

I am very inexperienced with linux, nodejs, and the raspberry pi, so any guidance would be appreciated. Thanks!

Pexeus commented 1 week ago

I think i know how you can fix this.

Source of the problem: You have not set up a system variable for node for your root user. I think this should be fixable by just reinstalling it as the root user or setting up a variable. (ask chatgpt to set it up so you dont need the absolute path as root)

Alternatively, you can modify onboard/standby/runner.js as you can see on line 36, the program expects a node system variable to be present. You can fix this by changing this line to noca = spawner("/home/test/.nvm/versions/node/v14.21.3/bin/node ./driver/index.js")