Hosting App
Hosting the Node JS app.
So we already have our node js app on this github repo, or the one that you created.We used the One Click apps to set up our droplet, so we have all the dependencies we need. If we hadn't done this, we'd have to follow these steps to do it run our app.
- Get into our droplet
- Install Git
- Install NodeJS
- Clone our repo
- Serve the app.
Get into droplet
Lets ssh into the droplet with the IP. Remember to replace the IP with your IP address from the Digital Ocean control panel. We should have a prompt like this.$ ssh root@138.197.80.147
root@nodejs-512mb-nyc3-01:~#
Note your terminal may ocasionally hang depending on
your internet connection, because SSH needs to maintian an open
connection. In case this happens, just close the terminal, and start
again. Install Git and NodeJS
We already have these installed. We can just confirm byroot@nodejs-512mb-nyc3-01:~# git --version
git version 2.7.4
root@nodejs-512mb-nyc3-01:~# node -v
v6.9.2
Clone repo and start the app
To clone the application,root@nodejs-512mb-nyc3-01:~#
git clone https://github.com/gangachris/DO-nodejs
root@nodejs-512mb-nyc3-01:~# cd DO-nodejs
root@nodejs-512mb-nyc3-01:~# npm install
root@nodejs-512mb-nyc3-01:~# npm start
This should start the application inside your droplet. If you open a new tab in your browse and go to <your_ip_address>:3000
, you should see the app running.
Awesome, right.
One problem though, if you close your ssh session, npm will stop and your app will be offline. We need to use something that will ensure our app keeps running.
We'll use forever js. Stop you running app with
Ctrl + C
root@ubuntu-512mb-nyc3-01:~/DO-nodejs# npm install -g forever
root@ubuntu-512mb-nyc3-01:~/DO-nodejs# forever start index.js
Going to <your_ip_address>:3000
on the browser should still be running your app. Our app will run forever.Stopping the app should be intuitive,
root@ubuntu-512mb-nyc3-01:~/DO-nodejs# forever stop index.js
That was the first approach. Let's look at the next one.
Comentarios
Publicar un comentario