I am new to linux and AWS. I have a node.js server running on an EC2 instance. I am running the following command to keep it running endlessly and on port 80:
$ sudo node app.js &
Now when I run it using
sudo my node application will not find any of the environment variables.
I need to be able to set environment variable USER, PASSWORD, and an IP to connect to my database. I have tried countless commands and only managed to set 1 environment variable but it gets deleted when I set a new variable.
I found what I was looking for thanks to the example Jeff Schaller gave below. I tried it exactly as it was but I'm not sure why it didn't work, I ended up learning a bit on shellscripts.
First I ran
$ vim runapp.sh. Then I added the following code :
#!/bin/sh Clear export USER="Username" export PASSWORD="Password" export IP="220.127.116.11" Node ./bin/www
After I saved the file, I ran
$ chmod +x runapp.sh
Finally I ran
$ sudo ./runapp.sh & and it ran perfectly.
If I should not be doing this or if there is an error or a better and safer way of doing it let me know so that I can fix it eventually.