29

Where is the conventionally accepted location of node.js/express web apps, in a linux file system?

Currently I've got a subdirectory in /opt/ but I'd like to hear other people's view on this...

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
UpTheCreek
  • 828
  • 3
  • 10
  • 17

2 Answers2

15

The /opt directory is a good location for the program distribution files. The /srv directory is used for the programs run-time data. (Please see the Filesystem Hierarchy Standard.) Unlike the /etc directory where the standard indicates that the /opt/<pkg> configuration files should be placed in /etc/opt/<pkg>, there is no standardization that /srv/opt/<pkg> should be a parallel structure (although it's probably not a bad idea).

In summary:

/opt/webserver/     (your node.js application)
    server.js
    package.json
    node_modules/
    ...

/etc/opt/webserver/
    config.json     (configuration file for your web server)

/srv/opt/webserver/ (opt subdirectory suggested, but not required)
    index.html
    images/
    css/
    ...

/var/opt/webserver
    error.log
    request.log

Please keep in mind that this is the general case, and is not unique to express applicaitons.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
Frank Hellwig
  • 151
  • 1
  • 4
  • 2
    Why did you recommend to put logs into `/var/opt/webserver` and not into `/var/log/webserver`? Is this a typo? – kaiser Feb 19 '16 at 12:39
  • On a Google Compute Engine running Debian should /opt or /srv directory be good enough to deploy a node application so the multiple users can access it with read/write permissions? – Rinav Nov 22 '17 at 06:00
  • What are the best permissions for the opt folder? – Iván E. Sánchez Jan 28 '19 at 20:30
4

The most appropriate place would be under /srv.

Ignacio Vazquez-Abrams
  • 44,857
  • 7
  • 93
  • 100