NodeJS + Cpanel Error : Incomplete response received from application (Node js, Express, Mongoose)

Viewed 2138

I have created a Node js application using express & mongoose and deploy it to the web server using cpanel. I use their feature "Setup Node JS" to deploy it to my subdomain. on the first 6-7 days, it runs well, all function & feature runs properly without any problem and nothing bad happened. But suddenly, there is an error said internal server error 500 when opening the page.

I searched here to find a solution and yes, I got some solution to add this line of code

RewriteCond %{ENV:REDIRECT_STATUS} 200

to my .htaccess file. And it works (I still don't get it why at first it also worked out without adding this) and I can get my page back again. Well, kind of...not entirely.

However...

Everytime I use my login or sign up feature in my program (basically when try to run mongoose method such as User.find({})) it will hung up for 2-3 minutes until the page says the error:

on page: Incomplete response received from application

on console : 502 Bad Gateway

I have searched here but didn't find anything yet, only this question that has similar problem yet it hasn't been answered clearly yet to me like what port that needs to be open? where can I find it.

I am a total noob on programming and just started it, so how should I solve that error?

At this point I am not really sure what to show you guys to make it more understandable but I'll include my .htaccess file below. Additionally, I tested it on heroku and it runs perfectly normal. But it needs to be served on cpanel shared hosting and it's a little bit more complicated.

Thanks for your help.

My .htaccess file contain this:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/intidina/psikotes"
PassengerBaseURI "/"
PassengerNodejs "/home/intidina/nodevenv/psikotes/12/bin/node"
PassengerAppType node
PassengerStartupFile index.js
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION BEGIN
<IfModule Litespeed>
</IfModule>
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION END

RewriteCond %{ENV:REDIRECT_STATUS} 200
1 Answers

First thing first, you cannot run MongoDB on shared hosting. Please refer to this thread..

This is consistent to your statement below:

Additionally, I tested it on heroku and it runs perfectly normal. But it needs to be served on cpanel shared hosting and it's a little bit more complicated.

If shared hosting deployment is a must, then an option is use external MongoDB instance. Fortunately, you had one when deploying in Heroku.

It is not explained in question, so I'll assume the Heroku app used mLab

  1. go to your Heroku Dashboard -> your app, https://dashboard.heroku.com/apps/your_app
  2. if you have installed mLab MongoDB add-on, go to its settings. It will redirect to https://www.mlab.com/databases/heroku_yourdbname
  3. In the setting menu, you will see options to connect using MongoDB URI, then it will display something like mongodb://<dbuser>:<dbpassword>@something.mlab.com:11331/heroku_yourdbname. Change and to your username and password respectively. Then make sure your hosting allowed port 11331.

Hope this helps.

Related