Skip to main content

Create a Node.js service in Zerops

Zerops provides a Node.js runtime service with extensive build support. Node.js runtime is highly scalable and customisable to suit both development and production.

Create Node.js service using Zerops GUI

First, set up a project in Zerops GUI. Then go to the project dashboard page and choose Add new service in the left menu in the Services block. Then add a new Node.js service:

Choose Node.js version

Following Node.js major versions are currently supported:

  • 18
  • 20
  • 22

You can change the major version at any time later.

Set a hostname

Enter a unique service identifier like "app","cache", "gui" etc. Duplicate services with the same name in the same project are forbidden.

Limitations:

  • maximum 25 characters
  • must contain only lowercase ASCII letters (a-z) or numbers (0-9)

The hostname is fixed after the service is created. It can't be changed later.

Set secret env variables

Add environment variables with sensitive data, such as password, tokens, salts, certificates etc. These will be securely saved inside Zerops and added to your runtime service upon start.

Setting the secret environment variables is optional. You can set them later in Zerops GUI.

Read more about different types of env variables in Zerops.

Set auto scaling configuration

Zerops scales the Node.js services automatically both vertically and horizontally. Vertical scaling means increasing or decreasing the hardware resources (CPU, RAM and disk) of a Node.js container. Horizontal scaling adds or removes whole containers.

Vertical auto scaling

Vertical auto scaling has following default configuration:

 Minimum resourceMaximum resource
vCPU120
RAM0.25 GB32 GB
Disk1 GB100 GB

Node.js service always starts with the minimal resources.

For most cases, the default parameters will work without issues. If you need to limit the cost of the Node.js service, lower the maximal resources. Zerops will never scale above the selected maximums.

When you are experiencing problems with insufficient Node.js performance or capacity, increase the minimal resources. Zerops will never scale below the selected minimums.

You can change the vertical auto scaling parameters later.

image

Horizontal auto scaling

When a container needs more CPU or RAM but already consumes maximal resources defined for the vertical auto scaling, Zerops will add a new container to your Node.js service. When your Node.js service doesn't need so much power and all containers are vertically scaled down in such a way their CPU allocation is near the minimal resources, Zerops will gradually remove whole containers.

Horizontal auto scaling has following default configuration:

minimum containers1
maximum containers6

Node.js service always starts with the minimum number of containers.

You can increase the minimum or decrease the maximum number of containers. The horizontal scaling parameters can be changed later.

Check if your application is ready for highly available mode. If not, set the maximum containers to 1. Zerops will never add more containers to your Node.js service.

You can keep the minimum at 1 container, but you should do so with caution and only for non-critical or dev services. Production grade service should start with at least 2 containers.

Learn more about Node.js auto scaling.

Create Node.js service using zCLI

zCLI is the Zerops command-line tool. To create a new Node.js service via the command-line, follow these steps:

  1. Install & setup zCLI
  2. Create a project description file
  3. Create a project with a Node.js and PostgreSQL service

Create a project description file

Zerops uses a yaml format to describe the project infrastructure.

Basic example:

Create a directory my-project. Create an description.yml file inside the my-project directory with following content:

# basic project data
project:
# project name
name: my-project
# array of project services
services:
-
# service name
hostname: app
# service type and version number in nodejs@{version} format
type: nodejs@latest
# defines the minimum number of containers for horizontal autoscaling
minContainers: 1
# defines the maximum number of containers for horizontal autoscaling. Max value = 6.
maxContainers: 6
# optional: create env variables
envSecrets:
S3_ACCESS_KEY_ID: "P8cX1vVVb"
S3_ACCESS_SECRET: "ogFthuiLYki8XoL73opSCQ"

The yaml file describes your future project infrastructure. The project will contain one Node.js version 20 service with default auto scaling configuration. Hostname will be set to "app", the internal port(s) the service listens on will be defined later in the zerops.yml. Following secret env variables will be configured:

S3_ACCESS_KEY_ID="P8cX1vVVb"
S3_ACCESS_SECRET="ogFthuiLYki8XoL73opSCQ"

Full example:

Create a directory my-project. Create an description.yml file inside the my-project directory with following content:

# basic project data
project:
# project name
name: my-project
# optional: project description
description: A project with a Node.js and PostgreSQL database
# optional: project tags
tags:
- DEMO
- ZEROPS
# array of project services
services:
-
# service name
hostname: app
# service type and version number in nodejs@{version} format
type: nodejs@latest
# optional: vertical auto scaling customization
verticalAutoscaling:
minVCpu: 5
maxVCpu: 10
minRam: 2
maxRam: 16
minDisk: 2.5
maxDisk: 50
# defines the minimum number of containers for horizontal autoscaling. Max value = 6.
minContainers: 2
# defines the maximum number of containers for horizontal autoscaling. Max value = 6.
maxContainers: 4
# optional: create env variables
envSecrets:
S3_ACCESS_KEY_ID: "P8cX1vVVb"
S3_ACCESS_SECRET: "ogFthuiLYki8XoL73opSCQ"
-
# second service hostname
hostname: db
# service type and version number in postgresql@{version} format
type: postgresql@12
# mode of operation "HA"/"non_HA"
mode: NON_HA

The yaml file describes your future project infrastructure. The project will contain a Node.js service and a PostgreSQL service.

Node.js service with "app" hostname, the internal port(s) the service listens on will be defined later in the zerops.yml. Node.js service will run on version 20 with a custom vertical and horizontal scaling. Following secret env variables will be configured:

S3_ACCESS_KEY_ID="P8cX1vVVb"
S3_ACCESS_SECRET="ogFthuiLYki8XoL73opSCQ"

The hostname of the PostgreSQL service will be set to "db". The single container mode will be chosen and the default auto scaling configuration will be set.

Description of description.yml parameters

The project: section is required. Only one project can be defined.

ParameterDescriptionLimitations
nameThe name of the new project. Duplicates are allowed.
descriptionOptional. Description of the new project.Maximum 255 characters.
tagsOptional. One or more string tags. Tags do not have a functional meaning, they only provide better orientation in projects.

At least one service in services: section is required. You can create a project with multiple services. The example above contains Node.js and PostgreSQL services but you can create a description.yml with your own combination of [services].

ParameterDescription
hostnameThe unique service identifier.

The hostname of the new database will be set to the hostname value.

Limitations:
- duplicate services with the same name in the same project are forbidden
- maximum 25 characters
- must contain only lowercase ASCII letters (a-z) or numbers (0-9)
typeSpecifies the service type nodejs and version.
Set type: nodejs@<version>

Limitations:
Following Node.js major versions are currently supported: 20,18,16
verticalAutoscalingOptional. Defines custom vertical auto scaling parameters.
minContainersDefines the minimum number of containers for horizontal autoscaling.

Limitations:
Current maximum value = 6.
maxContainersDefines the maximum number of containers for horizontal autoscaling.

Limitations:
Current maximum value = 6.
envSecretsOptional. Defines one or more secret env variables as a key value map. See env variable restrictions.

Create a project based on the description.yml

When you have your description.yml ready, use the zcli project project-import command to create a new project and the service infrastructure.

Usage:
zcli project project-import importYamlPath [flags]

Flags:
-h, --help the project import command.
--orgId string If you have access to more than one organization, you must specify the org ID for which the
project is to be created.
--workingDie string Sets a custom working directory. Default working directory is the current directory. (default "./")

Zerops will create a project and one or more services based on the description.yml content.

Maximum size of the description.yml file is 100 kB.

You don't specify the project name in the zcli project project-import command, because the project name is defined in the description.yml.

If you have access to more than one client, you must specify the client ID for which the project is to be created. The clientID is located in the Zerops GUI under the client name on the project dashboard page.

image

### Add Node.js service to an existing project

Example:

Create a directory my-project if it doesn't exist. Create an import.yml file inside the my-project directory with following content:

# basic project data
project:
# project name
name: my-project
# array of project services
services:
-
# service name
hostname: app
# service type and version number in nodejs@{version} format
type: nodejs@latest
# defines the minimum number of containers for horizontal autoscaling
minContainers: 1
# defines the maximum number of containers for horizontal autoscaling. Max value = 6.
maxContainers: 6
# optional: create env variables
envSecrets:
S3_ACCESS_KEY_ID: "P8cX1vVVb"
S3_ACCESS_SECRET: "ogFthuiLYki8XoL73opSCQ"

The yaml file describes the list of one or more services that you want to add to your existing project. In the example above, one Node.js service version 20 listening on the port 3000 with default auto scaling configuration will be added to your project. Hostname of the new service will be set to app. Following secret env variables will be configured:

S3_ACCESS_KEY_ID="P8cX1vVVb"
S3_ACCESS_SECRET="ogFthuiLYki8XoL73opSCQ"

The content of the services: section of import.yml is identical to the project description file. The import.yml never contains the project: section because the project already exists.

When you have your import.yml ready, use the zcli project service-import command to add one or more services to your existing Zerops project.

Usage:
zcli project service-import importYamlPath [flags]

Flags:
-h, --help the project service import command.
--projectId string If you have access to more than one project, you must specify the project ID for which the
command is to be executed.

zCLI commands are interactive, when you press enter after zcli project service-import importYamlPath, you will be given a list of your projects to choose from.

Maximum size of the import.yml file is 100 kB.