0

I have a bit of a remedial question about my first node.js web app.. This is the way I invoke my app:

me@mydevbox:/var/www/html/node/inventory$ node app.js 
model schema defined
successfully exported database schema
inside locations routing file
Listening on port 3030
connection successful

and then I use my browser to test it / run it etc.

If I now want to publish this app as a consumable resource for the rest of my team, how / what do I have to do to automate the process so that my app is always running? Sorry, I'm also fair new to sys admin stuff so any tips would be appreciated.

Happydevdays
  • 1,982
  • 5
  • 31
  • 57

2 Answers2

1

There is an npm package called forever that is used to achieve what you want.

See: https://www.npmjs.com/package/forever

forever

A simple CLI tool for ensuring that a given node script runs continuously (i.e. forever)

This question is also related to yours: Node.js as a background service

Community
  • 1
  • 1
  • cool. is this the standard way of deploying node apps into a production environment? – Happydevdays Aug 04 '16 at 13:45
  • I don't think is the standard way. I think in a production environment you would use a service (init script, systemd service, etc.) in order to run your nodejs app at startup and ensure is always running. See: http://stackoverflow.com/questions/4018154/node-js-as-a-background-service – Vicente Olivert Riera Aug 04 '16 at 13:49
-1

You can use the command nohup node app.js & to run the process and it won't stop when you close the terminal (on Linux). That way your app will keep running (as long as your server is running), and you only have to get the address to give to your team

G.P.
  • 75
  • 7
  • hi there. i just tested this and it does not work. specifically, i ran the command "nohup node app.js" and then tested the web app. it loads. Then i closed the command line, which kills the web app. – Happydevdays Aug 04 '16 at 14:12
  • And are you sure that something else didn't cause the end of the app ? If it's not the & and you're on Linux, it can only be an error in your app – G.P. Aug 04 '16 at 14:21
  • Hi again. I guess there could be errors in my app but no logs show errors and t's literally a few lines of code. :( – Happydevdays Aug 04 '16 at 14:36
  • Then I don't know what's the issue, `nohup node server.js &` works just fine for me and that's how I run my node.js apps. I use `pidof node` to see if node is still running, and you can always redirect the logs (since they won't show in console with `nohup`) with `&>` – G.P. Aug 04 '16 at 14:45