Knowledge Base
MilesWeb / Cloud Servers

Node.js Application Hosting on MilesWeb PaaS Cloud: The Latest Stack Versions Delivery with Docker Containers

Approx. read time : 8 min

The article comprises of the below points:

An open-source and cross-platform runtime environment, Node.js permits use of JavaScript for the client-side deployment as well as the server-side applications.

Recently, MilesWeb improved the Node.js stack template by integrating it with the support of Docker containers technology. Due to this, the delivery of Node.js server configuration and new engine versions became quite simpler and hassle-free.

The second major enhancement done in Node.js stack is the addition of new supported Node.js versions which are as below –

  • 6.x – legacy stable
  • 8.x – current stable
  • 9.x – mainline version comprising of latest features (still under development)

Below are the changes occurred due to this update along with the main specs of Node.js hosting implementation within MilesWeb PaaS.

Understanding the Node.js Stack Architecture in MilesWeb Cloud

The container-based approach is supported by MilesWeb PaaS for delivering stacks to end-users, each representing an isolated instance. This enables the platform orchestrator to automatically ensure that there is maximum high availability of your Node.js by distributing virtual server nodes from within a single environment across different physical nodes. This is called as anti-affinity.

When you host your Node.js application(s) with MilesWeb cloud, you automatically get number of extra advantages as below:

Your server lifecycle can be managed in a suitable way as the comfortable MilesWeb GUI enables you to perform steps like launching, scaling, restarting, stopping the node, deploying and updating application directly.

Quick update of container is essential for the Node.js developers since there is a frequent release of Node.js versions (once per month on an average). MilesWeb handles this process with safety and reduces your task by automatically creating and configuring new server each time a new Node.js version is released.

You can start working with your server immediately after its creation as the number of embedded package and process managers eliminate any preliminary manual tuning. The package managers –npm (used by default) and yarn are supported out-of-box while the preferred process manager can be set via the environment topology wizard.

While creating your Node.js server, you can choose your preferred process manager from npm, forever, supervisor and pm2, and also switch it any time later by simply clicking on Change environment topology button besides your Node.js environment for accessing the corresponding frame.

Note: If you have missed your favorite package or process manager, contact us so that we can elaborate and plan its integration in the near future.

How to Deploy Node.js App?

In order to deploy the Node.js application, one can deliver its source code to a platform in a view of .zip/tar.gz archive (either uploaded from the laptop or the publically available URL) or fetch it from a GIT/SVN repository.

Note: It is important to consider the following points prior to updating your Node.js application:

  • If you re-deploy a project with an archive, all the files previously stored within a container will normally be erased by the platform.
  • If you use a GIT repository as source code storage, the git pull command will be executed by the system when the update procedure is called. This will renew only the modified files.

How to Build Applications and Resolve Dependencies?

After the source code is fetched, MilesWeb will launch npm install (or yarn install, if it is set as a default package manager) in the root project directory to install/update all the packages, specified within the package.json.

How to Start a Node.js Server?

MilesWeb launches the Node.js server after the required packages are successfully installed. A command to be used for the process manager depends on the one which you have chosen. The commands include npm start, pm2 start, supervisor start or forever start.

However, there’s no need to panic, if the server doesn’t start after first attempt as it might happen due to one of the node’s port still appearing to be busy. In such situation, the Platform will try launching it at least 60 times with a one-second delay.

Suppose the main Node.js is listening to a custom HTTP port (i.e. neither 80th nor 8080th one), MilesWeb will automatically forward traffic from this port to the 80th one. This will help your application to be available across the Internet even if you aren’t using a Public IP address for it.

How to Stop a Node.js Server?

When you ask to Stop or Restart your Node.js server, the system will execute the kill -9 $NODE_PID command to shutdown its main process.

Troubleshooting Problems on a Node.js Server

MilesWeb keeps the information about all the occurred container lifecycle events by storing the executed commands list along with their output. So, in case you face any issue while deploying your Node.js application, you can always check the detailed information on the handled operations through the built-in Log manager.

If your Node.js server is scaled horizontally, you are able to browse the log files for each particular instance in a separate window.

A Guide to Server Tuning Possibilities

MilesWeb allows you to tune the Node.js process in a simple way which is possible due to the embedded option of Docker environment variables management at the Platform dashboard. Simply go to Additionally > Variables frame for the suitable container and change any required parameters via the comfortable graphical interface of MilesWeb control panel.

Following is a list of most commonly used variables:

  • PACKAGE_MANAGER (default is npm, you can set to yarn): It defines the utility to manage application packages and dependencies.
  • PROCESS_MANAGER (default is npm, you can set to pm2, supervisor and forever): It is used to select the process manager that will run the deployed application.
  • PROCESS_MANAGER_FILE: It provides the list of configuration options for process managers.
  • AUTO_OLD_HEAP (default is true, can be set to false): It is used to turn on/off the MilesWeb NodeJS memory auto configuration.
  • NODE_ENV (default is development): It is the variable used by popular Node.js frameworks like Express and similar ones.
  • APP_FILE (default is server.js): It displays the name of the main application executable file (i.e. the one that needs to be launched while starting the application). It is recommended to be specified as a file path, relative to the server Webroot directory.

How to Secure a Connection to Node.js Apps with SSL?

While securing your Node.js application hosted at MilesWeb PaaS, you can either use the embedded MilesWeb SSL feature (for internal domains) or Custom SSL (if your environment has an external domain bounded). Another alternative is to install the MilesWeb Let’s Encrypt add-on that offers the mentioned options free of charge.

Note: For utilizing the Custom SSL and Let’s Encrypt services for your Node.js application, your environment should include an NGINX Load Balancer node.

  • MilesWeb SSL feature allows you to get a security stamp for the required domain as well as guarantee the security of users’ private data at a low cost. You can enable it either while creating the environment or subsequently when you change the environment topology, through the environment topology wizard. For this, click on the SSL button above the topology structure and switch on the corresponding switcher.

  • To obtain the required level of security for custom environment domain name, it’s important to activate the Public IP address option for the preliminary added load balancer node in your environment. Then switch to the environment Settings > Custom SSL section and upload the correct certificate files.
  • The last option is install the Let’s Encrypt add-on that offers completely developed SSL certificates free of cost. For installing this tool, you need to go to Marketplace -> Add-ons section, select the Let’s Encrypt plank and click on Install button.

After few minutes, you will get the message for successful installation of a Let’s Encrypt addon to your environment.

Note: The validity of the automatically issued Let’s Encrypt SSL certificates in only for three months. In order to keep your application secured for all time, the platform will automate the request of a certificate update a month prior to the expiry data, apply it and then you will receive corresponding email notification.(You can accomplish this operation manually when required with the right option within add-on’s plank.)

How to Automatically Configure the Node.js Memory?

No doubt Node.js runtime is provisioned with embedded mechanisms of allocating dynamic memory and collecting garbage, you might face the need to improve the appropriate memory limits by manually setting up the required values.

This particularly concerns, the maximum heap size of Node.js which is basically set to predefined values of 512 MB or 1400 MB within all 32-bit and 64-bit systems respectively. This value calculation is done automatically in a MilesWeb PaaS, based on the total amount of memory, dedicated to a container each time you scale your Node.js server (either in or out). This behavior can be controlled by using the AUTO_OLD_HEAP variable. If the value is set to true, the —max-old-space-size value from the NODE_OPTS parameter is selected to set the optimal size of old heap space. This not only helps to eliminate memory errors but also optimize all the available memory for improving the performance of deployed applications.

The default —max-old-space-size is set equal to 90% of memory (RAM), assigned to a container. Yet if the difference between the amount of total memory and the —max-old-space-size is found to be less than 64MB, this variable value will be calculated based on the formula (total_RAM – 64MB). If you want to disable this optimization, you simply need to mention manually the required custom maximum heap size (in MB) within the NODE_OPTS variable. For eg: ‘–max-old-space-size = 128’.

So, MilesWeb offers all essential tools for installation and management of your Node.js applications. Along with the newly integrated support of the newest versions of this stack, you can reap the benefit of all the corresponding updates almost frequently after they are released.

After going through all the advantages of Node.js implementation, if you are interested in hosting your Node.js application with MilesWeb Cloud, you can opt for our one month free trial offered by us.

Avatar
Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.
Need help? We’re always here for you.