{"id":5155,"date":"2021-03-27T06:16:33","date_gmt":"2021-03-27T06:16:33","guid":{"rendered":"https:\/\/chemicloud.com\/kb\/?post_type=ht_kb&#038;p=5155"},"modified":"2022-04-04T11:24:01","modified_gmt":"2022-04-04T11:24:01","slug":"node-js-error-cannot-get-url","status":"publish","type":"ht_kb","link":"https:\/\/chemicloud.com\/kb\/article\/node-js-error-cannot-get-url\/","title":{"rendered":"How to fix the Node.js error: &#8220;Cannot GET&#8221; URL"},"content":{"rendered":"<p>Sometimes when using Node.js for your application(s) you may receive an error about the app being unable to &#8220;GET a URL&#8221;.<\/p>\n<p>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.<\/p>\n<p>For example, if the APplication URL text box is set to &#8216;mycoolapp&#8217; then the root path for the application is not &#8220;\/&#8221; but is actually &#8220;\/mycoolapp&#8221;.<\/p>\n<p>This behavior differs from most other web environments where \/ is typically the root path.<\/p>\n<p>This Knowledgebase article will cover how to resolve this error.<\/p>\n<p class=\"p1\"><b>Struggling with Node.js troubleshooting? ChemiCloud is the hosting solution designed to save you time! <\/b><span class=\"s1\">\ud83e\udd13<\/span><b> Check out our <\/b><span style=\"text-decoration: underline;\"><a href=\"https:\/\/chemicloud.com\/nodejs-hosting\/#60b65e4e63b58\" target=\"_blank\" rel=\"noopener\"><span class=\"s2\"><b>Node.js Hosting<\/b><\/span><\/a><\/span><b> plans!<\/b><\/p>\n<h3 id=\"how-to-fix-the-error-node-js-application-error-message-cannot-get-url\">How to fix the error Node.js application error message: &#8220;Cannot GET&#8221; URL<\/h3>\n<p>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.<\/p>\n<pre class=\"code\">const express = require('express');\r\nconst app = express();\r\n\r\napp.get('\/mycoolapp\/', function(req, res){\r\n    res.send(\"Hello from the root application URL\");\r\n});\r\n\r\napp.get('\/mycoolapp\/test\/', function(req, res){\r\n    res.send(\"Hello from the 'test' URL\");\r\n});\r\n\r\napp.listen(0, () =&gt; console.log('Application is running'));<\/pre>\n<p>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.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes when using Node.js for your application(s) you may receive an error about the app being unable to &#8220;GET a URL&#8221;. 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&#8230;<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"ht-kb-category":[211],"ht-kb-tag":[],"class_list":["post-5155","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-node-js"],"_links":{"self":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/5155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/comments?post=5155"}],"version-history":[{"count":4,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/5155\/revisions"}],"predecessor-version":[{"id":7251,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/5155\/revisions\/7251"}],"wp:attachment":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/media?parent=5155"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb-category?post=5155"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb-tag?post=5155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}