[Tutorial] How to run Node.js apps on cPanel

Hello, This is Jammie from iFastnet. In this tutorial we’re going to setup a nodejs application on cPanel First I enter the file manager and create a folder for my application Now in SSH I run “npm init” command in the folder to create a package.json file for the project I leave the default settings here, you may enter your own project info I choose app.js as the index file of my project the package.json file is created, now I install express.js express.js module is also installed let’s create the index file of our application I copy the hello world example application of express.js into the index file Now we need to tell the web server to serve our node.js app, we do this through .htaccess file First we need to enable showing hidden files in the file manager then we create a file called .htaccess in the root folder of our domain which is the public_html folder In the .htaccess file we need to add these directives Note the index file of our application is defined here “app.js” and you need to replace ifastnet with the username of your cpanel hosting the folder of our application is also defined here as myapp We’re all set, I save the file and refresh my website to check my node app ! Voila ! It’s our node app saying hello world There’s an important note here, let’s change the hello world message of our app I append a test string to our hello world message and when I refresh the page you see the message is not updated That’s because here is a production environment and we need to reset the webserver each time we change our code We can reset the web server by “pkill -9 Passenger” command, note the capital P in Passenger and the message is now updated ! Happy coding !

25 Replies to “[Tutorial] How to run Node.js apps on cPanel”

  1. Hi, I have problems with static files. Can you help ? <script src="/socket.io/socket.io.js"></script> and I get 503 (Service Unavailable). Same for images, css, js that are in client directory

  2. Hi ,Dear

    Check my this Support Ticket #607636 and solve my problem. you every time only wrote I have escalated this ticket to second line support, they will get back to you soon . kindly don't do that solve my problem.

    Thank you.

  3. I have this error "Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request." any body can help me?

  4. I have purchased VPS Grow Plan. I am not able to see cPanel dashboard like shown in video.
    I have to deploy Node JS app on VPS , How should I proceed ? Steps for the same would be a great help

Leave a Reply

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