Autostarting NodeJS Apps¶
You can have all of your NodeJS applications spin up automtically as soon as you
This can be achieved by makeing use of
(Node.js Process Manager) and the
Read more about how to add scripts for autostart commands:
Table of Contents
Simply add a script ending by
.sh to the
autostart/ directory that will accomplish this.
The following example will make use of
to spin up your NodeJS application.
- Path to your NodeJS project (within the Docker container):
- Name of the JS file to startup:
Add the following script to
su -c "cd /shared/httpd/my-node/src; pm2 start index.js" -l devilbox
- The whole command is wrapped into
suto ensure the application will be started as the user
cdtells it to you enter the directory where
index.jscan be found
Once the Devilbox is running, you can enter the PHP container and verify with
pm2 list that
everything is running as expected.
Instead of writing multiple scripts for multiple applications, you can also make use of the pre-shipped script that allows you to start unlimitted NodeJS applications via pm2 .
The following script is provided in
autostart/run-node-js-projects.sh-example and needs to be
copied to a file ending by
host> cd /path/to/devilbox host> cd autostart host> cp run-node-js-projects.sh-example run-node-js-projects.sh
If you also want to know how to reverse proxy your NodeJS service and have it available via the web server including HTTPS support have a look at the following links:
Imagine you have started an application within the PHP container that creates a listening port (e.g.: NodeJS). This will now only listen on the PHP container and you would have to adjust the docker-compose.yml definition in order to have that port available outside to your host OS.
Alternatively, there is a simple way to reverse proxy it to the already running web server and even make use of the already available HTTPS feature.