When creating a Node.js container there are a few ways to go about it, depending on your application and needs.
In this article we will cover setting up a standalone Node.js application with custom ports. We will also talk about using an Nginx proxy to handle web assets, images and resources when your Node.js application is used as a web service.
Once the container has been started, upload your files to the Container using your SSH/SFTP user. By default all Node.js containers will try and look for the file /container/application/app.js
. If your Node.js application file is named differently or in another location, you can edit the configuration file located at /container/config/supervisord.conf
changing the command
line accordingly.
command=/usr/local/bin/node /container/application/app.js
Restart the Container using the Control Panel to apply the configuration changes.
If your Node.js application is used as a web application, you may need a proxy in front to handle static assets, images and other resources. If that's the case, you can start by creating an nginx proxy just like any other web container.
Once you have created your nginx proxy Container, edit the nginx configuration file located at the path /container/config/nginx/sites-available/default
. You should see the commented out lines as per the below:
#upstream nodejs44 {
# server NODE_CONTAINER_HOSTNAME:8080;
#}
# proxy_pass http://nodejs44/;
Uncomment the lines above, replace the NODE_CONTAINER_HOSTNAME
with the hostname for your Node.js Container and save the configuration file. Reboot the nginx Container to apply the configuration changes.
The hostname for the Node.js container can be found within the Container management page in the SiteHost Control Panel, note that the hostname is not the same as the container label.
The standard output messages should be logged to the path /container/logs/supervisor/nodejs-stdout.log
whereas the standard error stream should be logged to the file located at /container/logs/supervisor/nodejs-stderr.log
.
If you apply changes to your application and can't see the changes live, try restarting the nginx proxy and browsing to your app using the incognito or private window.