Please enable JavaScript to view this site.

CloudLinux Documentation

Russian
English

Navigation: Node.js Selector

Command Line Interface

Below is a list of commands hoster and end user can run in a command line.

Hoster

Get information related to Node.js: default version, list of supported versions, status of Node.js Selector, list of users, their applications, etc:

cloudlinux-selector [get] [--json] --interpreter nodejs

 

JSON output for get command:

{
 "selector_enabled": true | false,
 "default_version": "6.11.3",
 "result": "success",
 "timestamp": 1508667174.220027
 "cache_status": "ready"         //  or “updating” during automatic yum cache rebuild
 "available_versions": {   //  begin of  “versions”
     "6.11.3" : {   //   begin of version "6.11.3"
                "name_modifier": "",
                "status": "enabled",  //  enabled, disabled, not_installed, installing, removing
               “base_dir”: “/opt/alt/alt-nodejs6”   //  empty when version is not installed
               “users”: {   //  begin of  “users”
 
                   “user1”: {   //  begin of “user1”
         “homedir”: “/home/user1”,                
                       “applications”: {    //  begin of “applications”
                          “apps_dir/app1” : {   //   begin of application “apps_dir/app1”
                              “domain”: “cltest1.com”,
                              “app_uri”: “apps/my-app1”,
                                     “app_mode” : “development”,
                               “startup_file” : “app.js”,
                              “app_status” : “started”,   // ‘started’ or ‘stopped’
                              “config_files” : [
                                   “package.json”,
                                   “gruntfile.js”
                               ],
                               “env_vars” : {
                                   “var1” : “value1”,
                                  “var2” : “value2”
                               },
                           },   // end of application “apps_dir/app1”
                          “apps_dir/app2” : {    //   begin of application “apps_dir/app2”
                                << data for application “apps_dir/app2”  (same structure as for application “apps_dir/app1” above) >>
                           },   //  end of application “apps_dir/app2”
                      },   //  end of “applications”
                    },   //  end of “user1”
                    “user2”: {   //  begin of “user2”
                        << data for user “user2”  (same structure as for “user1” above) >>
                   },   //  end of “user2”
                },   // end of “users”
              },    //  end of version “6.11.3”
           "8.21.5" : {   //   begin of version "8.21.5"
                 << data for version "8.21.5"  (same structure as for version “6.11.3” above) >>
              },    //  end of version “8.21.5”
          },    //  end of “versions”
}   //   end of json

 

Set default version, supported versions, and status of Node.js Selector:

cloudlinux-selector set [--json] --interpreter nodejs (--selector-status <enabled,disabled> | --default-version <str> | --supported-versions <str>)

Note that Node.js Selector is disabled by default. If an available Node.js version is not installed Node.js Selector is always disabled and it is impossible to enable it.

 

To set default Node.js version, please use the following command (note that required Node.js version should be enabled):

cloudlinux-selector set --json --interpreter=nodejs --default-version=<ver>

Examples:

This command enables Node.js Selector:

 

cloudlinux-selector set --json --interpreter nodejs --selector-status enabled

 

This command sets default Node.js version as 6:

 

cloudlinux-selector set --json --interpreter nodejs --default-version 6

This command sets supported Node.js version as 8:

cloudlinux-selector set --json --interpreter nodejs --supported-versions='{"6": false, "8": true}'

Install required Node.js version:

cloudlinux-selector install-version --json --interpreter nodejs --version 8

Uninstall required Node.js version:

cloudlinux-selector uninstall-version --json --interpreter nodejs --version 8

Enable required Node.js version:

cloudlinux-selector enable-version --json --interpreter nodejs --version 8

Disable required Node.js version (note that it is impossible to disable default Node.js version):

cloudlinux-selector disable-version --json --interpreter nodejs --version 8

Change version for application(s):

cloudlinux-selector set [--json] --interpreter nodejs ((--user <str> |  --domain <str>) --app-root <str> | --from-version <str>) --new-version <str>

Examples:

This command changes version for the specific application:

cloudlinux-selector set --json --interpreter nodejs --user user1 --app-root apps_dir/app1 --new-version 8

Common output for all set commands:

 

in case of success:

{
 "result": "success",
 "timestamp": 1508666792.863358
}

in case of error:

{
 "result": "Some error message",
 "details" : "Traceback: ..." ,
 "context": {},
 "timestamp": 1508666792.863358
}

in case of warning:

{
 "result": "success",
 "warning" : "Some warning message" ,
 "context": {},
 "timestamp": 1508666792.863358
}

To resolve issues related to install-version/uninstall-version commands (because they are running in the background) you may use this log file /var/log/cl-nodejs-last-yum.log

It contains full yum output from the latest performed operation (install or uninstall) and it will be rewritten with each operation.

 

End User

 

WARNING: options --user and --domain are mutually exclusive now.

 

 

 

Get config file for the user applications

 

cloudlinux-selector read-config [--json] --interpreter nodejs  [(--user <str> |  --domain <str>)] --app-root <str> --config-file <name>

JSON output:

{
       "result": "success",
       "timestamp": 1508666792.863358
         "data": "content of config file as Base64 encoded string"
}

 

Example:

 

This command gets config file for user1’s application app1:

cloudlinux-selector read-config --json --interpreter nodejs  --user user1 --app-root app_dir/app1 --config-file package.json

Save config file for the user applications

cloudlinux-selector save-config [--json] --interpreter nodejs  [(--user <str> | --domain <str>)] --app-root <str> --config-file <path> --content <content of config file as Base64 encoded string>

JSON output (the same as for all set commands):

{
       "result": "success",
        "timestamp": 1508666792.863358
}

 

Example:

This command saves config file for user1’s application app1:

=

cloudlinux-selector save-config --json --interpreter nodejs  --user user1 --app-root app_dir/app1 --config-file package.json  --content                                        VGh1ICAyIE5vdiAxMDo0MzoxMiBFRFQgMjAxNwo=

Get a list of applications for the specific user

cloudlinux-selector [get] [--json] --interpreter nodejs  [(--user <str> |  --domain <str>)]

 

Example:

This command gets a list of applications for the user1:

cloudlinux-selector get --json --interpreter nodejs  --user user1

Create user application

 

cloudlinux-selector create [--json] --interpreter nodejs [(--user <str> | --domain <str>)] --app-root <str> --app-uri <str> [--version <str>] [--app-mode <str>] [--startup-file <str>] [--env-vars <json string>]

Example:

This command creates user1's application for the domain xyz.com:

cloudlinux-selector create --json --interpreter nodejs --user user1 --app-root my_apps/app1 --app-uri apps/app1

or

cloudlinux-selector create --json --interpreter nodejs --app-root my_apps/app1 --domain xyz.com --app-uri apps/app1

Start, restart, stop, and destroy user application

cloudlinux-selector (start | restart | stop | destroy) [--json] --interpreter nodejs  [(--user <str> | --domain <str>)] --app-root <str>

 

Example:

This command starts user1's application:

cloudlinux-selector start --json --interpreter nodejs --user user1 --app-root my_apps/app1

Change properties for an application

 


cloudlinux-selector set [--json] --interpreter nodejs  [(--user <str> | --domain <str>)] --app-root <str> [--app-mode <str>] [--new-app-root <str>] [--new-domain <str>] [--new-app-uri <str>] [--new-version <str>] [--startup-file <str>] [--env-vars <json string>]

 

Example 1:

This command sets a production mode, new domain new.xyz.com, new Node.js version 8, new URI, new application root directory and new startup file for user1 application located on the domain xyz.com:

cloudlinux-selector set --json --interpreter nodejs  --user user1 --app-root my_apps/app1 --mode production  --new-app-root new_apps/new_app1  --new-domain new.xyz.com --new-app-uri new_apps/app1  --new-version 8  --startup-file new_app.js --env-vars '{ "var1" : "value1", "var2" : "value2" }'

Example 2:

cloudlinux-selector set --json --interpreter nodejs  --domain xyz.com --app-root my_apps/app1 --mode production  --new-app-root new_apps/new_app1  --new-domain new.xyz.com --new-app-uri new_apps/app1  --new-version 8  --startup-file new_app.js --env-vars '{ "var1" : "value1", "var2" : "value2" }'

 

 

Note that when changing Node.js version all replies from web application to get request will be checked in Node.js Selector (before and after version changing). HTTP response codes and MIME type are comparing. So, make sure application is available via http(s) at least locally.

 

 

Run npm install command for the user application

cloudlinux-selector install-modules [--json] --interpreter nodejs  [(--user <str> |  --domain <str>)] --app-root <str>

Example:

This command runs npm install for user1 application:

 

cloudlinux-selector install-modules --json --interpreter nodejs --user user1 --app-root my_apps/app

 

 

Note that all replies from web application to get request will be checked in Node.js Selector (before and after modules installation). HTTP response codes and MIME type are comparing. So, make sure application is available via http(s) at least locally.

 

 

Run a script from package.json file of a user application, arguments <args> are passed to the script

cloudlinux-selector run-script [--json] --interpreter nodejs  [(--user <str> | --domain <str>)] --app-root <str> --script-name <str> [-- <args>...]

Example:

cloudlinux-selector run-script --json --interpreter nodejs --user user1 --app-root my_apps/app --script-name test_script -- --script_opt1 --script_opt2 script_arg1 script_arg2

JSON output:

 

{
        "result": "success",
        "timestamp": 1508666792.863358
        "data": "script output as Base64 encoded string"
}

Activate virtual environment of NodeJS:

source <home_of_user>/nodevenv/<app_root>/<nodejs_version>/bin/activate

 

This command changes prompt to

Example:

[newusr@192-168-245-108 ~]$ source /home/newusr/nodevenv/newapp4/newapp3/8/bin/activate
[newapp4/newapp3 (8)] [newusr@192-168-245-108 ~]$

 

After ativation user can use npm and node from a virtual environment without full paths.