9 thoughts on “[Tutorial] How to build websites with A2 Shared Hosting part 2: Set up Node.js using cpanel

  1. Well… thank you for such a basic set up. What about running a real-world production-ready app, like express that connects third party services over SSL? 

    Here are my 2¢ after a full day of trying to figure this out.

    Before you set up your node app, make sure your app is working correctly, locally, and on A2's server via SSH. Use whatever logger you want, but make sure you remove any console calls — console.error will halt your app.

    Assuming you are in A2's cPanel > Setup Node.js App
    01. When you create an application, the application's root refers to the root of the account, NOT the public_html folder where HTML/PHP files are hosted to display your site.
    02. It is not clear what the Application URL's function is all about — but use the node app's name sans the .js extension
    03. The Application startup is the 'app.js' filename that contains your spiffy node app
    04. Via A2's cPanel or SSH upload the package.json from your node app to the folder Setup Node.js App created on the server  — make sure all dependencies are listed.
    05. DO NOT install the node's dependencies through SSH $ npm install.
    06. Refresh the Setup Node.js App page, and it will now show a "Detected configuration files" and [ > RUN NPM Install ] button.
    07. Press Run NPM install — Setup Node.js App will install the node_modules in the allowed place and create a symbolic link in the app's folder
    08. Start the app — sort of.
    09. Next to the [ > RUN NPM Install ] button, a [ Run JS Script ] button will appear.
    10. Click on the Run JS Script button. It will show the node scripts you set up in the package.json, let's assume you have a "start": "node server.js"
    11. Click on the “start” script.
    13. The two buttons above will be replaced by a "Running Script… Oo.oOo. (animation)"
    14. Done. Close window.

    NOTES:
    Keep in mind if the app crashes, cPanel will not restart the node app. You'll need to look at the npm log files and the logger for the culprit.

    A few Gotchas:
    Do not rename, or move the folder created by Setup Node.js App — you will not be able to delete the app in Setup Node.js App.

    cPanel folks, Herokus does it right.

  2. hi im currently having a problem in connection to my mongoDB atlas database when i deployed my nodejs app in a2hosting is there a work around to this?

  3. https://stackoverflow.com/questions/60256417/node-js-rest-api-not-working-plesk-hosting-server/60256884?noredirect=1#comment106632068_60256884

  4. Thank you so much.. This helps me to clear my doubts and directed me to the right path. I have similar web hosting and I want to thank you very very much,… 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *