0

I am doing a chat app and integrating it on a website. When i execute teh command 'node index.js' on the local server everything works fine. But when i try installing node js on a dedicated server and try to execute the command 'nohup node index.js &' through ssh it gives following message.

nohup: ignoring input and appending output to `nohup.out'

I had followed the method mentioned in this site for installation of node js on server https://www.a2hosting.com/kb/installable-applications/manual-installations/installing-node-js-on-managed-hosting-accounts

Can someone help me, please?

  • Try running `node` app using `pm2` manager in production. – Mukesh Sharma Dec 24 '16 at 11:02
  • Can you please explain in detail @Mukesh Sharma – Prabha Chetty Dec 24 '16 at 11:13
  • This can help you. http://stackoverflow.com/documentation/node.js/2975/deploying-node-js-applications-in-production/21325/deployment-using-pm2#t=20161224111450433553 – Mukesh Sharma Dec 24 '16 at 11:14
  • apparently it's normal behavior : http://stackoverflow.com/questions/24646320/nohupignoring-input-and-appending-output-to-nohup-out – Radioreve Dec 24 '16 at 12:05
  • I have tried it, neither any message will be displayed on the terminal nor my chat app is working @Radioreve – Prabha Chetty Dec 26 '16 at 05:38
  • Did [my answer](https://stackoverflow.com/questions/41312651/how-to-run-node-js-on-dedicated-server/41313267#41313267) below answer your question? If so then you may consider [accepting the question](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) so that other people who search it could see that it has an accepted answer. – rsp Dec 27 '16 at 18:20

1 Answers1

1

You first need to install Node in a correct way. I wrote a tutorial about it: How to get Node 6.7.0 on Linux (of course you can use newer versions, just change the version in the commands).

Basically it's something like this - change the version to the one you like:

# change dir to your home:
cd ~
# download the source:
curl -O https://nodejs.org/dist/v6.1.0/node-v6.1.0.tar.gz
# extract the archive:
tar xzvf node-v6.1.0.tar.gz
# go into the extracted dir:
cd node-v6.1.0
# configure for installation:
./configure --prefix=/opt/node-v6.1.0
# build and test:
make && make test
# install:
sudo make install
# make a symlink to that version:
sudo ln -svf /opt/node-v6.1.0 /opt/node

I recommend building Node from source and always running make test but you can also install a binary package which is faster - just make sure you understand the issues with paths and hashbang lines if you do so - more info on that and more install options are described in my tutorial.

Then you need to make sure that your application is started every time the server is restarted. I recommend using Upstart if you can.

Using Upstart, save something like this in /etc/init/YOURAPP.conf:

# When to start the service
start on runlevel [2345]

# When to stop the service
stop on runlevel [06]

# If the process quits unexpectadly trigger a respawn
respawn

# Start the process
exec start-stop-daemon --start --chuid node --make-pidfile --pidfile /www/YOURAPP/run/node-upstart.pid --exec /opt/node/bin/node -- /www/YOURAPP/app/app.js >> /www/YOURAPP/log/node-upstart.log 2>&1

Just change:

  • YOURAPP to the name of your own app
  • /opt/node/bin/node to your path to node
  • /www/YOURAPP/app/app.js to the path of your Node app
  • /www/YOURAPP/run to where you want your PID file
  • /www/YOURAPP/log to where you want your logs
  • --chuid node to --chuid OTHERUSER if you want it to run as a different user than node

(make sure to add a user with a name from --chuid above)

With your /etc/init/YOURAPP.conf in place you can safely restart your server and have your app still running, you can run:

start YOURAPP
restart YOURAPP
stop YOURAPP

to start, restart and stop your app - which would also happen automatically during the system boot or shutdown.

For more info see those answers about:

You can also use systemd for that but there are some differences as the system is much more complicated and often leads to some problems.

Community
  • 1
  • 1
rsp
  • 107,747
  • 29
  • 201
  • 177