The take off your node.js app from localhost on laptop into the Internet can be a bit painful. In general shared web hostings don’t allow for hosting node.js apps. You can use however AWS, VPS, dedicated servers, Digital Ocean, A2 Hosting, NodeChef, Heroku etc, but interfaces there can be a bit confusing at start, if you got used to Cpanel management. Also, the above solutions are not necessary that cheap, unless you need basic app functionality only.
Now, there is possibility to get Node.js and Express.js working on Cpanel account. However, you do need WHM or root access to the server first. After simple command line operations as root, you log in via ssh as user, and use Cpanel graphic interface to prepare environment for your Node.js app.
First of all, folders for your Node.js apps will be in user home directory, NOT under public_html (default document root), so your application will be available at URL like: www.userdomain.com/mynodeapp. Actually the whole process takes less than 10 minutes just to get started. Full details are available at the below link:
and the screenshots show simple Cpanel interface allowing you to to add Node.js apps and manage them.
With Edit option:
The Cpanel Application Manager assumes that you main app is app.js NOT index.js. To change it, you have to edit the files:
After that execute commands:
However & But
Well, there are some issues however. As long as you follow the default, Cpanel recommended settings for Node.js application all seems to be OK, at least for basic scenarios. However, there is probably some lack of functional synchronicity / functional agreement between node index.js/app.js executing server, and Enable/Disable options in Applications Manager. Testing files upload, for instance, I got error: Incomplete response received from application, which unfortunately can mean many things, depending on circumstances it was generated.
I have also tested nodemon and it just didn’t work, so to be able to update output on screen I have to jump between shutting down local Node.js server and Enable/Disable settings of Applications Manager. I didn’t use app.js as default/main application (I used index.js) and maybe for more advanced application I should rebuild http server, maybe restart it or maybe to modify something somewhere else – I don’t know, and to find the answer it can take much time. From my point of view, for basic things Cpanel approach to Node.js apps can work, and the Cpanel company is definitely on the right track, but probably it is still too early to get on Cpanel hosting Node.js/Express applications working like on services with functionality dedicated to Node.js/Express.