Node.js – ChemiCloud Knowledge Base & Self-Support Center https://chemicloud.com/kb Fri, 29 Mar 2024 09:30:53 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.2 https://chemicloud.com/kb/wp-content/uploads/2019/06/favicon_rk1_icon.ico Node.js – ChemiCloud Knowledge Base & Self-Support Center https://chemicloud.com/kb 32 32 How to fix the Node.js error: “Cannot GET” URL https://chemicloud.com/kb/article/node-js-error-cannot-get-url/ https://chemicloud.com/kb/article/node-js-error-cannot-get-url/#comments Sat, 27 Mar 2021 06:16:33 +0000 https://chemicloud.com/kb/?post_type=ht_kb&p=5155 Sometimes when using Node.js for your application(s) you may receive an error about the app being unable to “GET a URL”.

You are receiving this because the Node.js implementation in cPanel uses Phusion Passenger to manage Node.js apps. When you create an application in the Node.js cPanel, too, Passenger uses the value in the Application URL text box to create the root path.

For example, if the APplication URL text box is set to ‘mycoolapp’ then the root path for the application is not “/” but is actually “/mycoolapp”.

This behavior differs from most other web environments where / is typically the root path.

This Knowledgebase article will cover how to resolve this error.

Struggling with Node.js troubleshooting? ChemiCloud is the hosting solution designed to save you time! 🤓 Check out our Node.js Hosting plans!

How to fix the error Node.js application error message: “Cannot GET” URL

You need to include the application URL in your routes to resolve this problem. The following code sample demonstrates how to do this using the popular Express web application framework. It assumes that the Application URL text box in the Node.js cPanel tool is set to mycoolapp.

const express = require('express');
const app = express();

app.get('/mycoolapp/', function(req, res){
    res.send("Hello from the root application URL");
});

app.get('/mycoolapp/test/', function(req, res){
    res.send("Hello from the 'test' URL");
});

app.listen(0, () => console.log('Application is running'));

In this code sample, two routes are defined, /myapp and /myapp/test. If your domain name is example.com, and you use your web browser to view http://example.com/myapp or http://example.com/myapp/test, the pages load as expected. However, if you visit any other URL under http://example.com/myapp, you receive the Cannot GET error message.

 

 

]]>
https://chemicloud.com/kb/article/node-js-error-cannot-get-url/feed/ 5
How to Set up Node.js Application in cPanel https://chemicloud.com/kb/article/how-to-set-up-node-js-application-in-cpanel/ https://chemicloud.com/kb/article/how-to-set-up-node-js-application-in-cpanel/#respond Wed, 18 Sep 2019 16:43:37 +0000 https://chemicloud.com/kb/?post_type=ht_kb&p=2520 In this tutorial, you will learn you to easily set up Node.js applications with the cPanel graphical interface or from the command line.

ChemiCloud’s infrastructure supports Node.js out of the box. If you’d like to experience top speed and reliability and have access to our easy Node.js installer, try our Node.js Hosting plans.

Please note that Node.js Application in cPanel is available for customers using any of our Shared Hosting or Reseller Hosting plans. If you are a Managed VPS Hosting customer, you’ll require a CloudLinux License –  Please get in touch with our Support team for pricing.

How to Set up Node.js Application in cPanel

Create the application

1) Log in to cPanel.
2) In the SOFTWARE section of cPanel, click on the Setup Node.js App icon


3) On the Node.js selector page, click on the Create Application button to start the application setup.

Fill in the required fields on the application setup form.

  • Node.js version – select your preferred Node.js version from the drop-down list.

    The supported versions are 8.17.0, 9.11.2, 10.24.1, 11.15.0, 12.22.9, 14.20.1,16.17.1, 18.14.1 and 20.10.0

  • Application mode – choose Development or Production from the drop-down list. You can choose Development initially and change it to Production later on.
  • Application root – the file system location for the application files. The entry will be appended to /home/username to form the complete path to the application files in the cPanel home directory.
  • Application URL – the public URL to your application.
  • Application startup file – the initial file that will be processed when launching the application.

4) When the form is complete, click the Create button.

package_json

5) After the application is created, an information box is displayed advising that the package.json is required to continue.

The application will launch and display a test page. If you want to see if the test page works, Click the Open button.

6) Click the Cancel button to continue.

Now that a working application is installed, the environment can be enhanced with the package.json settings file and the npm package manager. To install package.json and npm, follow the steps in the next two sections.

Create the package JSON

1) Go back to cPanel’s dashboard. In the FILES section of cPanel, click the File Manager icon to open the File Manager.

2) In the left-hand column of File Manager, click the text of the application root folder.

3) Click the +File button to create a new file.

In the New File dialog box, enter the file name package.json and then click the Create New File button.

4) Once the file is created, Right-click or secondary click on the package.json file in the right-hand column of File Manager and then click Edit. An edit dialog box is displayed.

5) In the Edit dialog box, click the OK button and enter the following text in the editor screen

{
"name": "app",
"version": "1.0.0",
"description": "My App",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

6) Click the Save Changes button to save the file.

7) Click the Close button to close the editor.

Install NPM

1) In the SOFTWARE section of cPanel, click on the Setup Node.js App icon

2) In the Actions column of the Web Applications list, click the pencil icon to edit the application.

3) Click the Run NPM Install button.

The NPM installation runs and presents a success indicator when completed:

Node.js
NPM Install completed successfully

To install packages with NPM and do other command-line tasks related to the application, log in via SSH and enter the virtual environment for the application using the command shown in the information box at the top of the application setup page.

How to Set up Node.js Application using Command Line

If you are familiar with using SSH, you may find the command line interface faster and easier than using the cPanel install interface.

To set up a node.js application from the command line, follow these steps:

1) Connect to your account via SSH.
2) Create the Node.js application with the following command:

cloudlinux-selector create --json --interpreter nodejs --version 11 --app-root app --domain example.com --app-uri app

3) Once you are inside your account’s home directory, change to the application directory

cd ~/app

Open your preferred text editor and create the package.json file. In our example, we’ll use the vi editor.

vi package.json

press i to change to insert mode and paste the following text into the editor.

{
"name": "app",
"version": "1.0.0",
"description": "My App",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

Press Escape key followed by : to enter command mode.
Press x followed by Enter key to save and exit the vi editor.

4) Install npm by entering the following command.

cloudlinux-selector install-modules --json --interpreter nodejs --user example --app-root app

To install packages with NPM and do other command-line tasks related to the application, log in via SSH and enter the virtual environment for the application using the command

source /home/example/nodevenv/app/11/bin/activate && cd /home/example/app

That’s a wrap! Now you know how to set up a Node.js app using the cPanel or command-line interface. 

]]>
https://chemicloud.com/kb/article/how-to-set-up-node-js-application-in-cpanel/feed/ 0