Search code examples
node.jsmongodbrestubuntu

NodeJS Broken Pipe causing my Express api to stop working


I have looked for answer for this question and have to find anything quiet like what I experience!

I set up an Ubuntu instance on AWS, standard configurations, medium tier.

I ssh into the server, and then I have a script running in Node, which I launch with sudo nodejs server.js .

When it runs, it has a few REST endpoints which work just fine, and those write to a mongodb (which, also works just fine). However, if I leave my computer and come back the next day, I get the standard SSH broken pipe, which is fine. But! When I try to use my REST api at that point, the node server.js is clearly not running.

I am the only person consuming this api, so I don't think errors are bringing it down.

Has anyone experience anything like this? Perhaps there is a configuration I am missing?


Solution

  • A friend just answered it for me,

    sudo nodejs server.js & > mylog.out

    This makes it run in the background and print the stdout to a log instead of nowhere (nowhere due to broken pipe)