How to host your Node.js App on a shared hosting server

Nweke Charles
6 min readJan 19, 2020

Hello there, it’s your man Charles and I’m back once again to give you a guide on how to host your Node.js App on a shared hosting server. Please pay good attention and follow everything i say and do and if you have further questions I will drop my Twitter handle in the conclusion section so you could reach out to me.

Lets begin

If you have ever hosted your Node.js App then there is a high possibility that it was hosted on Heroku or Digital Ocean. So I wanted my Node.js App, Database and Web App to be located in one place and not just scattered all around then I started searching for a shared hosting server that runs Node.js with an easy setup and by easy I mean no terminal just GUI’s that you have to click here and there to get what you want and luckily I came across Namecheap. I guess I have spoken a lot so let’s get down to it.

Steps on hosting your Node.js App on Namecheap

  • The first step is to buy your domain Name and Hosting plan then head into your Account dashboard and it should look something like the image below.

Navigate to Domain List > Products and notice an arrow pointing to a button pointing downwards, click on it and a section should drop down showing cpanel, also click on it and you should be taken to your control panel.

  • Your cpanel should look something like this

though not this small but you should be able to locate the section in the image and when you have located it click on the Setup Node.js App and you should be taken to a page where you set up your Node.js App

  • After you must have clicked on Setup Node.js App you should get a page looking like this.

Now click on CREATE APPLICATION and you will be taken to a page like this

  • Select your node.js version as for me I’m using version 12.9.0 which is available in the options
  • Set your Node App to development or live not sure its live but you get what i mean
  • Application root: Enter the folder name with which you want your Node app files to be in.
  • Application URL: Fill in a name with which you want your API to be accessible through. E.g api.
  • Application startup file: this can be left empty or you put in the name of the file that has all your end points and I will suggest either app.js or server.js maybe because that’s what almost everyone uses but if the field is left empty and you click create it automatically adds an app.js file to your folder which contains your node.js App files.
  • Click create.
  • Now your Node App has successfully been created and you will see a page like this

We are almost there. Notice that there is an orange circle with a question mark in it

that signifies that there isn’t any Package.json file present in your Node App folder so you have to add and how do we do that, by heading back into the Dashboard of our cpanel by clicking on the box shape which the black arrow points to,

when this is done you should be taken back to cpanel now scroll down a bit while looking for file manager, if found click else keep searching. 😂😂😂Funny i just wrote an if else statement I think I deserve a clap for that hahaha,

Anyways back to base. So when file manager is clicked on

you will be taken to a page where all your necessary and important folders and files are located which should look something like this

and you should see the folder name you put into Application root while creating the Node.js App. Click on the folder you created and you will see a public folder, tmp folder and probably an app.js file or server.js file depending on what you did while creating the Node App. You have to upload your Node app files so zip them up and click on the upload text above while you are in your Node app and drop your zipped folder of your node app. Note do not zip your node modules folder. When you are done uploading click on the back link below and your node folder should look like this without the node modules folder.

Before we step out of here right click on your app.js or server.js file and select Edit, a pop up box should show click on edit. You should see some code in the file but if you see nothing its still cool. I will be dropping my app.js code which I copied and pasted in the app.js file on my server.

Note your express server should not listen to any port and if you’d notice the endpoint above /ap should be /application-URL you set while creating the Node app also not all the packages required are needed to run this app but never the less it will still work. Now save the file and head back to your cpanel and click on the Setup node.js app, you will see this page

with your node app you created now click on the pencil like icon and you will be taken to a page like this

but with a little bit difference. The Run NPM Install will be clickable now with a new button beside it that says Run js Script or something of that sort. Stop the app then click on Run NPM install which will install all your dependencies thereby dropping the node modules folder in your Node.js App folder on the server. When this is done it gives you a notification at the top right corner of the page. Now the same place you stopped the app you’d see a text in blue background “START APP” click on it and wait for some seconds and the app is running now scroll down to Application URL and you will notice and open text beside the input field,

click on it and wala you endpoint is working which should look like this

Conclusion

So that’s it nothing more than this to host your Node / Express.js app on a shared hosting server specifically Namecheap. It might be the same on some other providers and it might be different. So please if you have any questions at all kindly hit me up on Twitter or drop a comment I will reply to it as soon as possible until then have a nice day.

--

--

Nweke Charles

Ui developer, React.Js enthusiast, Next.Js developer, game freak and so much more. Don't forget to hit the follow btn 😎