Deploy your application
Running your app on server
Connnect to your server :
LocalMachine
$username@serverDomainName
We would advice you to create your projects folder on your home directory using the following command:
VirtualPrivateServer
$mkdir projects && cd projects
After changing to your /projects folder you should clone your website git repo with the following command :
VirtualPrivateServer$git clone git@github.com:username/repo.git
Then finally you will Install all your npm modules by running the next following command:
VirtualPrivateServer
$sudo npm install -g && sudo npm install --save
NB
The -g
flag installs node_modules
GLOBALLY as a result YOU WILL NOT HAVE node_modules
folder to Exist on your local project files. The--save
flag installs node_modules
folder and it saves it locally inside your project. At this stage you should be having your updated .gitignore file existing because of the (git pull) command that you’ve ran onto the terminal, no more package.json file modification. If you want to make other changes then it would mean this file should be last modified when you first ran npm install node_module-name
from your local machine;
You now need run :
VirtualPrivateServer
$pm2 start index.js
- you can replace the
index.js
file withapp.js
orserver.js
depending on the express server code that you implemented to your file.
What’s next ?
…
Go to your browser and type your application url:
url=http://yourServerName:appsPORTNUMBER
OR
If you are arleady on your local machine terminal you can just type do the following depending on the browser of your choice:
google-chrome http://yourServerName:appsPORTNUMBER
Same Applies for firefox
firefox http://yourServerName:appsPORTNUMBER
Just one last Tip to update your application
software is always changing ...
-
You need to update your app on your your local machine and push your changes to github
-
Connect to your server again and change to your project’s directory then run git pull command:
VirtualPrivateServer
$git pull
Remeber!
- After pulling you have to restart your remote server pm2 program <
application-id
> using the following command:
VirtualPrivateServer
$pm2 restart your <application-id>
OR
pm2 restart your <application_name
> based on the pm2 first column of <Diagram.1
> when you where checking pm2 status with the following command :
VirtualPrivateServer
$pm2 status
If you don’t know the id of your app you will then type the following command :
VirtualPrivateServer
$pm2 status
(In this case we are having four deployed apps) so the following is going to be our Output ~>
Diagram.1
You will then follow this procedure again and again …
Then you’re DONE!