How to Install Node App in CPanel of GoDaddy

Jay Chow
3 min readFeb 18, 2019

Most of us use shared hosts for a very simple web host. Have you ever think about how to host a server on the shared host and make your node app instead of using PHP application on GoDaddy?

# First thing to do:

wget -qO- https://cdn.rawgit.com/creationix/nvm/master/install.sh | bash

# Second validate your source file

source $HOME/.nvm/nvm.shnvm install stable

# Now check the version of your node and npm

nvm ls

You would see something like this:

# Then, go to public_html folder and create htaccess file and

cd ~/public_htmlnano .htaccess

# Copy information below, (3000) is the default port for express, change whatever port that you are going to setup

RewriteEngine On
DirectoryIndex disabled
RewriteRule ^$ http://127.0.0.1:3000/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:3000/$1 [P,L]

# Now your folder should be contain those:

drwxr-x---  3 abcdef nobody       4096 Feb 17 23:19 ./
drwx--x--x 19 abcdef abcdef 4096 Feb 17 23:17 ../
-rw-r--r-- 1 abcdef abcdef 1699 Jul 3 2014 404.shtml
drwxr-xr-x 2 abcdef abcdef 4096 Feb 17 23:05 cgi-bin/
-rw-r--r-- 1 abcdef abcdef 1963 Jul 3 2014 home.html
-rw-rw-r-- 1 abcdef abcdef 208 Feb 17 23:19 .htaccess
-rw-r--r-- 1 abcdef abcdef 4282 Jul 3 2014 layout-styles.css

Once you finish your installation, go to express site to copy some of the startup code

mkdir myapp
cd myapp
npm init -y
npm install express --save
touch index.js

Don’t forget to copy this code to your index.js file:

const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => res.send('Hello World!'))app.listen(port, () => console.log(`Example app listening on port ${port}!`))

Now you are almost complete everything.

All you need is to make the server run all the time and no matter it crashes or updates

# install the forever start package on your server

npm i pm2 -g

# since the pm2 is very handy tool, you just run this command to run the server and restart by adding — watch tag

pm2 start index.js --watch

--

--

Jay Chow

Full Stack Developer — Typescript | Javascript | NodeJS | Python |MongoDB | ReactJS | VueJS | EmberJS — Blog writer & Professional writer❤️ @ shijiezhou.com