I have understood the problem and founded the solution !!
A big thank to @Brahma Dev and @TGrif for their help !
The problem was that on the server I have node.js install globally (via apt-get) and an other version installed a the user which launch npm run dev
And if I execute su myuser -c "node -v
, su doesn't execute .bashrc before node -v
.
So if I execute su myuser
and then node -v
, the version of node is different !
I have solved the problem by creating an sh script containing :
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
npm run dev
And now, su myuser -c "./start-server.sh"
works !
So if I add su myuser -c "/var/www/dialoguea.co.tools/dialoguea/start-server.sh" &
in /etc/rc.local the node.js server loads when ubuntu is restarted.