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

[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 !


Leave a Reply

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