31

I'm running 4 separate Node.js apps on a Linux server with different ports and a proxy in front.

As I'm (right now) the only user in the server, it doesn't matter where I place the apps and how to run them. Currently my apps stay under my home directory (~/app1/, ~/app2/, etc.).

So my question is: where should I place the apps so that they can be shared between multiple users? Is there a standard place similar to /var/www?

jsalonen
  • 29,593
  • 15
  • 91
  • 109
  • 3
    possible duplicate of [How to deploy node.js?](http://stackoverflow.com/questions/4681067/how-to-deploy-node-js) – Matt Ball May 29 '12 at 13:10
  • 1
    True, that question solves my problem partly. I will rephrase the question. – jsalonen May 29 '12 at 13:13
  • 1
    What do you mean by "shared between multiple users"? Do you plan to run each app more than once at the same time? – ziad-saab May 29 '12 at 13:19
  • 1
    Good question. Like with Apache you have `www-data` and `/var/www`. Is there some common, similar practise for node.js? – jsalonen May 29 '12 at 13:31

4 Answers4

15

I use https://github.com/visionmedia/deploy to deploy my apps. It will create a /var/www/productname directory. Inside that directory you have source, current and shared. The shared directory has the log and pid files.

I found that a good directory structure so that's what I am using for all my projects.

Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
Pickels
  • 33,902
  • 26
  • 118
  • 178
  • Deploy seems really nice, thanks! I will be trying that out soon to see it myself and will get back to you. – jsalonen May 30 '12 at 12:24
  • I think `/var/nodejs` is better / safer since `/var/www` was used by web servers like Apache in the past (instead of the new standard `/var/www/html`). Using `/var/www` for Node.js apps could add a risk of having all your server-side source code visible to unauthorized users. – baptx Jul 23 '19 at 07:44
13

I run Apache in addition to Node.js on the same server, so I don't really like having applications for Apache and Node.js in the same directory. My Apache hosted applications go in the traditional /var/www/ path, and I put my Node.JS applications under /var/node/. This is due to some automation I have setup in both Apache (Dynamic Virtual Hosts) and Node.JS.

More information on my setup and automating Proxy and Apache deployment can be found here: How to use vhosts alongside node-http-proxy?

Community
  • 1
  • 1
Timothy Strimple
  • 22,920
  • 6
  • 69
  • 76
4

If you are using AWS Elastic beans stack for Node JS application on Linux server, then it should be there in /var/app/current/ directory

Misa Lazovic
  • 2,805
  • 10
  • 32
  • 38
vikky MCTS
  • 162
  • 1
  • 6
4

Following the guidelines of the answer here - https://serverfault.com/a/96420 indicates that /opt/node might be a better places for this, since it'a catchall directory that's reserved for user added program files

chrismarx
  • 11,488
  • 9
  • 84
  • 97
  • Don't you mean /opt? – Richard Ayotte Jun 09 '17 at 16:39
  • I think the right answer is actually /srv - https://unix.stackexchange.com/questions/35807/recommended-location-of-node-js-applications-in-linux-filesystem – chrismarx Jun 29 '17 at 15:58
  • 2
    I feel like apps should be in /opt and files served in /srv and in the Node.js case, it's an app, not shared files. http://www.pathname.com/fhs/pub/fhs-2.3.html#OPTADDONAPPLICATIONSOFTWAREPACKAGES – Richard Ayotte Jun 29 '17 at 18:18