Have a Question?
How to use Node.JS
Node.JS based programs can be run in our hosting packages. To run the programs, the following settings must be made on the storage.
Use in default CGI mode
It is possible to run NodeJS scripts via the
#!/bin/env node shebang line and the appropriate Apache handler in cgi mode. If the Node.JS program you want to run is jscrpt, then you need to add the appropriate Apache administrator. Use cPaneles File Manager or an FTP client to connect to the storage space and then log in to the library where you uploaded the files and folders of the program.
Create a .htaccess file and upload it with the following content:
AddHandler cgi-script .jscript
The setting can be set globally, in this case the entire storage will be valid.
In this case, log on to the cPanel interface and then find the Apache Keypad in the Advanced Settings box.
On the page that appears, add the following extension in the Create an Apache Handler section:
Click the Add button.
You can test your storage settings by creating the following popup file. Make a file with the text editor (for example, Notepad ++) with the following content:
#!/bin/env node console.log("Content-Type: text/html;charset=UTF-8\n"); console.log("Hello World!");
Save the file as a test.jscript file under UNIX standard lineup (LF), then upload it to your storage. After uploading, the file must be set to 755 or rwxr-xr-x. You can modify the privilege using the FTP client program. Then, in the browser, call the prepared page (http://yourdomainname.tld/test.jscript) here in Hello World! must be inscribed.
Set up alternative CGI mode
After making the settings in this description, the .js files from the browser will be run by the cgi-bin/cgi-node program. To use CGI-Node.js, download the latest release from http://www.cgi-node.org/downloads.
They suggest that you download the cgi-node.min.js file, as this web site provides faster service. Rename the downloaded file to cgi-node, open with a text editor and replace the first line with:
Next, find the SessionPath variable in the file. Set a variable as a directory that can not be accessed through a browser. For example: /home/YOUR_CPANEL_USER_NAME/tmp/cgi-node-session. Then save the file and then upload it to your cgi-bin folder. Also set a 755 privilege for the file.
If you specify a non-existent directory in the file, you will create it on your storage after uploading it.
Next, create a .htaccess file in the root directory of the web site with the following content.
Action cgi-node /cgi-bin/cgi-node AddHandler cgi-node .js
To test your settings, you need to create a file with a text editor in your site’s root directory. The file contains the following content:
For example, save the created file, for example, as body.jscript, then call the page (http://yourdomainanme.tld/test.jscript). Your browser will display a spreadsheet that will show the variables in the run environment.