0

I am able to run my node server on an EC2 instance by SSH-ing into the server and running the command node index.js when inside of the src file. The server works fine, but the issue is that I have to persist the SSH connection to the EC2 instance, otherwise it terminates the server process. I'm sure I'm doing something wrong, but I couldn't find a clear cut and dry solution online without getting too much into the weeds.

Also for anyone wondering, I SSH-ed into my github and installed git on the EC2 instance in order to pull the code from the repository to the instance, instead of using CodeDeploy. The reason is that I was getting vague errors with CodeDeploy like "there was an issue deploying your revision", so I decided to go the manual route for uploading the code. So I could use some solutions to common "gotchas" in this area as well. Thanks.

1
0

One very lame thing to do is to install tmux and just run the node server inside a tmux session - that should be used only for testing and dev experiments, not much more.

Another option is to wrap your node service as an OS service (e.g. systemd) and let the OS manage the lifecycle of the application for you.

Yet another option is to bundle the service as a Docker container and let Docker (or docker-compose) to run and manage it.

Finally, I'd prefer to choose a managed AWS solution like AWS Beanstalk to actually deploy a long-running service. They will take care of automatically applying patches to your server(s) and will make it easy to deploy new versions.

1
  • Thanks! I appreciate all the different options. What's the reason tmux should only be used for testing/development? Would you say the same with wrapping the node service as an OS service? Apr 29 at 9:10
0

To start service in background and deattach it from your ssh session execute the command on this way:

nohup node index.js &

nohup will deattach if from the terminal/ssh & will put it in background

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.