Node.js Usage & Configuration



Search Results

Node.js is a popular choice for building modern web applications and is supported by Probo.CI. You can build your entire application with Node.js or use it to compile assets such as CSS stylesheets from SASS or other Javascript components you would like to build on the fly. By default, Node.js version 22 is the version specified to run inside of Probo.CI.

Option 1: Using Node.js As Part Of Other Applications (PHP, Dotnet, Drupal, etc)

To specify a default version of Node.js to use, you can add the nodejs tag to your .probo.yaml file. For example, to use Node.js version 18, you would add the following to your .probo.yaml file:

nodejs: 18

You are not limited to using this version of Node.js for your entire build. You can use different versions of Node.js in different build steps by using the nvm command to switch versions. For example, to use Node.js version 8 in a build step, you would add the following to your .probo.yaml file:

1
2
3
4
5
6
  - name: Build Assets
    commands:
      - cd $SRC_DIR/path/to/your/js-or-sass/files
      - nvm install 8
      - npm install
      - npm run build

Note that your package.json must be in the directory you are executing npm from. If you are using a different directory, you will need to navigate to that directory before running npm install and npm run build.

Option 2: Building a Standalone Node.js Application With NodeJSApp Plugin

If your appliction is a Node.js application and not part of another stack, you can build it by itself and set it up to serve your Node.js application. To do this, you utilize the nodejs application type in conjunction with the NodeJSApp plugin.

You can still use the settings as specified above to use specific versions of Node.js but you can execute your Node.js application in a build step by using the NodeJSApp plugin. You can also install databases, solr, and other technologies as part of your application. There are some required settings to make this work:

  • database {string}

    The name of your asset database file to be imported into the database you have specified in the database tag of your .probo.yaml file. The asset must be in the assets array of your .probo.yaml file. If the database is gzipped or bzipped you can use the databaseGzipped or databaseBzipped tag to specify that the database is compressed.

    Example
    1
    2
    3
    4
    5
    6
    # Set a custom directory for your application
    steps:
      - name: Setup NodeJS Application
        plugin: NodeJSApp
        database: node-js.sql.gz
        databaseGzipped: true
  • subDirectory {string}

    The subdirectory of your git repository where your app lives. This is where your package.json, yarn.lock, or package-lock.json is located.

    Example
    1
    2
    3
    4
    5
    # Set a custom directory for your application
    steps:
      - name: Setup NodeJS Application
        plugin: NodeJSApp
        subDirectory: web
  • buildCommand {string}

    This is the command used to build your application. This occurs before your runCommand directive. This is optional and defaults to npm install.

    Example
    1
    2
    3
    4
    5
    # This will run yarn to install your application and fetch dependencies.
    steps:
      - name: Setup NodeJS Application
        plugin: NodeJSApp
        buildCommand: yarn
  • runCommand {string}

    This is the command used to execute your application. This occurs after your buildCommand directive. This is optional and defaults to pm2 start npm -- run build.

    Use of pm2

    The pm2 package has been installed by default on all NodeJSApp containers. We strongly recommend using this for Probo.CI Node.js builds. Without it, builds are likely to hang on the execution step and never finish. While it will be available at the permlink URL, the “View Site” button on the interface won’t lite up. You will see how we converted npm run prod to pm2 in the example below.

    Example
    1
    2
    3
    4
    5
    6
    7
    # Set the command for executing the application
    steps:
      - name: Setup NodeJS Application
        plugin: NodeJSApp
        subDirectory: web
        buildCommand: yarn
        runCommand: pm2 start npm -- run prod
  • globalPackages {array}

    A list of packages to be installed prior to build command. In our example we will install yarn globally and then use it to build the application and use an npm command to execute the application. This is the first step in the build process. It is optional and need not be specified if you have no global dependencies.

    Example
    1
    2
    3
    4
    5
    6
    7
    8
    9
    # Install yarn as a global package prior to build and execution.
    steps:
      - name: Setup NodeJS Application
        plugin: NodeJSApp
        subDirectory: web
        buildCommand: yarn
        runCommand: pm2 start npm -- run prod
        globalPackages:
          - yarn
  • environment {hash}

    This is a hash of environment variables passed to the application. By default, probo’s global environment variables are passed to the application. This is optional and need not be specified if you have no additional environment variables to pass.

    Example
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    # Pass our database connection information to the application via environment variables.
    steps:
      - name: Setup NodeJS Application
        plugin: NodeJSApp
        environment:
          NODE_ENV: production
          LOG_LEVEL: trace
          DB_HOST: localhost
          DB_PORT: 5432
          DB_USER: root
          DB_PASSWORD: strongpassword
          DB_NAME: probo

Below is a completye example of a .probo.yaml file for a Node.js application. It uses the version 18 of Node.js in conjunction with PostgreSQL and a NodeJSApp plugin to build and run a Node.js application. It downloads yarn globally and uses it to build the application and then runs npm run prod to execute the application.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
type: nodejs
database: postgres:16
nodejs: 18

assets:
  - node-js.sql.gz

steps:
  - name: Setup NodeJS Application
    plugin: NodeJSApp
    database: node-js.sql.gz
    databaseGzipped: true
    subDirectory: web
    buildCommand: yarn
    runCommand: pm2 start npm -- run prod
    globalPackages:
      - yarn
    environment:
      NODE_ENV: production
      LOG_LEVEL: trace
      DB_HOST: localhost
      DB_PORT: 5432
      DB_USER: root
      DB_PASSWORD: strongpassword
      DB_NAME: probo
Get Started with Probo.CI

Want to Try Probo today?
Get Started Fast!.

When you sign up for a Probo.CI registration code, you will get a two week trial of the plan of your choosing. For more information on how to get started, click here .

LEARN MORE ABOUT PROBO.CI'S PRICING