How-to
    How To Add Google AdSense To Your Website
    How To Download Canvas as an image
    How To Embed Youtube Videos
    How To Host NodeJS Apps
    How To Host Static Websites On Amazon AWS EC2
    How To Host Static Websites On Amazon AWS S3
    How To Host Static Websites On GCP Cloud Storage
    How To Install Node.js
    How to Speed Up IntelliJ IDEA / Clion
    How to safely store API Keys

How To Host NodeJS Apps

Updated: 2022-02-21

Install Node by downloading from the official website.

Install forever:

$ npm install forever -g

Modify Apache config file: /etc/apache2/sites-available/000-default.conf(Ubuntu)

<VirtualHost *:80>
    ServerName app.example.com
    ProxyPreserveHost on
    ProxyPass / http://127.0.0.1:2368/
    ProxyPassReverse / http://127.0.0.1:2368/
</VirtualHost>

Make sure the port is correctly set. Now restart Apache server:

$ sudo apachectl restart
AH00526: Syntax error on line 50 of /etc/apache2/sites-enabled/000-default.conf:
Invalid command 'ProxyPreserveHost', perhaps misspelled or defined by a module not included in the server configuration
Action 'restart' failed.
The Apache error log may have more information.

if you see the above error message, enable proxy first:

$ sudo a2enmod proxy
Enabling module proxy.
To activate the new configuration, you need to run:
  service apache2 restart

$ sudo a2enmod proxy_http
Considering dependency proxy for proxy_http:
Module proxy already enabled
Enabling module proxy_http.
To activate the new configuration, you need to run:
  service apache2 restart

then restart again:

$ sudo apachectl restart

If you got 500 Internal Server Error, make sure proxy_http is enabled

$ ls /etc/apache2/mods-enabled/