How to execute Node.js and Python commands
Why?
The environment for Python and Node.js sites is installed in the user's home directory. Therefore, if you enter commands from the server console without setting up a virtual environment, the commands may not work as expected or may not work at all.
Instructions
The panel shell client
To execute commands, we recommend using the shell client in the panel.
Go to the "Sites" section and select a required site with a Node.js or Python handler. Then, click on the "three dots" menu on the right and select "Shell client".
In a newly opened tab, enter the necessary commands.
The shell client launches under the site owner. When the terminal is open, perform the following actions:
- Change the working directory to the website's home directory;
- Add the path to the virtual environment for the selected site to the $PATH variable.
Terminal
To work directly from the terminal, export the path to the site handler to the environment variable $PATH
or enter the full path to the handler executable file.
PLEASE NOTE!
The steps described are provided as an example and have only been tested on Ubuntu 20.04. The sequence of actions may differ on other operating systems.
By default, handlers are located in the site's home directories:
- For Node.JS -
/var/www/<username>/data/.nvm/versions/node/<nodejs_version>/bin/
- For Python -
/var/www/<username>/data/www/<site-name>/.venv/bin/
The factual path to the handlers can be found in the settings of a specific site. Go to the "Sites" section, select the desired site and click on the "Edit" button.
Сonnect to the server via SSH under the user-owner of the site and go to the root directory of the desired site using the following command:
cd ~/www/<site-name>
To execute the command, specify the path to the handler itself before the command. For example:
/var/www/<username>/data/.nvm/versions/node/<nodejs-version>/bin/node script.js
Another way is adding the path to the handler to the environment variable $PATH
:
export PATH="<path-to-the-handler>:$PATH"
For example:
- For Node.JS -
export PATH="
var/www/<username>/data/.nvm/versions/node/<nodejs-version>/bin/"
- Python -
export PATH="
var/www/<username>/data/www/<site-name>/.venv/bin/"
This method of adding a path to the environment is effective for the duration of the current session. To ensure the path is permanently included in the environment, add the command to the shell configuration file. For example, for the "bash" shell, the relevant file can be found at /home/<username>/.bashrc
.
After making changes to the file, reconnect to the server or run the following command:
source ~/.bashrc