guilin 桂林
guilin 桂林

Reputation: 17422

how to setup nodejs webapp as service?

I have nodejs installed, npm installed, modules installed, and my app codes. On my dev machine I simply type node app.js in my app folder to start the dev server, but now it's the time to deploy it to a real server I got problem.

  1. Where is the regular folder to place my app codes.
  2. Which user should be use to run my nodejs app. and how to make the user only have permission to execute app codes, and 80, 443, 843 ports.
  3. How to write the service script, and stop server by kill pid?

Upvotes: 3

Views: 1754

Answers (2)

Pono
Pono

Reputation: 11786

I recommend Monit with Upstart. You can read about that solution here and here. You can also make a simple load balancer in nginx.

Upvotes: 1

Raynos
Raynos

Reputation: 169451

ports are determined by which port your app listens on. If you have physical access via ssh to a server and have root privileges etc then you can just treat it as a dev server.

I would recommend forever for keeping it running and maybe a writing a balancer to handle multiple node apps at once.

Permission handling has to be done based on connectivity. A user connects to your service and you authenticate it for its permission levels. This is done by hand.

The folder you place it is not very relevant.

If you have say a no.de server you can learn how to use their smart machines. THere are similar guides for say the Amazon EC2.

Upvotes: 4

Related Questions