Creating a NodeJS application container
When creating a NodeJS 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 NodeJS application with custom ports. We will also talk about using an Nginx proxy to handle web assets, images and resources when your NodeJS application is used as a web service.
Navigate to the 'Containers' module. If you're about to create your very first container, you should see a message similar to the one shown below. Click the 'Add Container' button in the upper right corner of the page to get started:
Select the 'Service' tab, then choose the 'NodeJS' option. You can additionally change the name of your container on this page, for now we will leave this as 'nodejs44'.
On the next step you will be presented with some additional options that you wouldn't normally see when creating a regular web container. In this example we will be adding an SSH/SFTP user, an additional port, as well as changing the containers entrypoint.
3.1. Adding a SSH/SFTP user.
3.2. Publishing Ports
By default all containers can connect to a NodeJS container on port 8080, if you need to publish a port so it is accessible directly from a remote location, you can enter up to five (5) ports here.
3.3. Custom Entrypoint
By default all NodeJS containers will try and look for the file '/container/application/app.js'. If your NodeJS application file is named differently or in another location, you can change this here.
Once the container has been started, simply upload your application and restart the container. Restarting the container is required in order for node to automatically start your application.
Logs for your application can be found in the following locations:
If your NodeJS application is used as a web application, you may need a proxy in front to handle static assets, images and other resources.
You can create an nginx proxy just like any other web container.
At the time of writing, when creating an Nginx proxy it is already configured to connect to a NodeJS container named 'nodejs44'. If for some reason you changed your container name, or you want to use the proxy for other another use, you will need to edit the default nginx configuration to suit your needs.