Skip to content

Creating a Node.js Application Container

There are a few ways to create a Node.js container. The best option depends on your application and other requirements.

This article shows you how to set up a standalone Node.js application with an Nginx proxy to handle web assets, images and resources when your Node.js application is used as a web service.

NodeJS is a Service Image. See Creating a Container for the first steps to follow.

The guides below assume that your NodeJS container is running, and that you have SSH/SFTP access to it.

Uploading Files

Upload your files to the Node.js container as an SSH/SFTP user. By default all Node.js containers will look for the file /container/application/app.js. If your Node.js application file is named differently or in another location, edit the configuration file located at /container/config/supervisord.conf to change the command line

command=/usr/local/bin/node /container/application/app.js

Reboot the Container to apply your configuration changes.

Nginx Proxy

If your Node.js application is used as a web application, you might need a proxy in front to handle static assets, images and other resources. If so, you can create an Nginx Proxy Web Container as easily as any other. Create an SSH/SFTP User when you do, because there’ll be some configuration changes to make.

SSH into your Nginx Proxy Container, and edit the Nginx configuration file located at the path /container/config/nginx/sites-available/default.

You’ll see some lines that are commented out:

#upstream nodejs44 {
# proxy_pass http://nodejs44/;

Uncomment these lines, replacing the NODE_CONTAINER_HOSTNAME with the hostname for your Node.js Container. Save the configuration file, then reboot the container to apply the configuration changes.

Debugging your Node.js application

Standard output messages should be logged to /container/logs/supervisor/nodejs-stdout.log. The standard error stream should be logged to /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 an ‘incognito’ or ‘private’ window.