This post describes the exact steps to deploy a NodeJS app on GoDaddy shared hosting.
- Log in to GoDaddy account and click Manage Hosting
- In settings, click server and make sure SSH access is on
- Click manage against SSH access and note down the credentials
- Install a tool (Putty, MobaXTerm, etc.) to connect to the server using SSH
- Once connected cd into the directory where you want to deploy a NodeJS app. It will be public_html for main domain or public_html/ in case of subdomain
- run the command: wget https://nodejs.org/dist/v6.9.2/node-v6.9.2-linux-x64.tar.xz
- Above command will install the node in your directory
- Upload your app in zip format and extract in the directory where you want to run the app
- run the command node app.js &
- If you find an error, make sure to add the code inside the .htaccess file (code available at the end of the list)
- To stop existing NodeJS app first run any one of the commands: ps -ef | grep node OR ps aux | grep node
- The above command will give you all the running processes, take note of the process id (2nd column from left) you want to stop
- Now run the command: kill -9 PROCESS_ID
- That’s all. Enjoy 🙂
.htaccess code:
RewriteEngine on
RewriteRule (.*) http://localhost:3000/$1 [P,L]
DirectoryIndex disabled