hello in this video I am going to look
at how to deploy your bot written in
nodejs to a server and that server being
one that runs on a service called Heroku
so let's take a look at the pieces so
you can see here I have my browser open
to my test account a twosie ITP
which I most recently just tweeted a bot
tweeted a random number 39 and I have
the code for that bot open right here
you can see it in sublime it's very
simple it has a single function that
tweets that random number and then I
also have my terminal open to that
directory and I could just really
quickly test to make sure that bot works
the bot is starting it worked let's go
back to the browser I'm going to hit
refresh and we can see now I got random
number four so everything is working the
point is in this videos I want to say
this bot that's running right over here
I don't want to run it from my laptop I
want it to run autonomously on a server
somewhere that I can set it to go and
never think about it again
so let's pull it tweet it to get let's
quit it and look at how we can do that
so the site that I've deserted the
service that I'm going to use in this
particular video is Heroku so you'll
need an account so you know if you're
watching this video and you don't have a
Heroku account go to Heroku comm Heroku
spelled this way dot-com and you can see
here I went there now I'm already logged
in so it went straight to my dashboard
and you could see that I have all these
things already listed on my dashboard
because apparently I've tried to make a
variety of I've tried to do this a whole
bunch of time to test this test that
elite soon etc so what are these things
these things are referred to as dinos I
think that's right not dinos di nos
dinos dy nos like a dynamic thing that's
running it's a process that you're
running so what I need to do is create a
Dino to run my bot so the very first
thing that I'm going to do is go up here
to this plus sign up in the top right
and I'm going to say create new app so
app does really what I'm doing I'm going
to create an app
I'm going to call it a coding rainbow
demo should only contain lowercase
letters okay rainbow demo it is
available I'm going to create it and it
is now there so there's a whole bunch of
things I need to do here and one of the
things about using Heroku is Hiroko is
kind of its own animal it's not really
an animal it's a web server but whatever
it's it's its own it has its own way of
doing things and the way that you send
things to Roku and get things back from
Heroku is two ways one is you use git
what is git oh boy if you don't know
what get is stay tuned for my upcoming
set of git and github tutorials but for
now if you don't know what get is you're
gonna be you'll still be able to follow
this but you're just gonna have to
verbatim kind of copy I heard a noise
there's a person somewhere nearby I have
to keep going anyway okay you can just
reverb eight and copy some of these
commands um okay so now I'm waving to
somebody who but it's my neighbor Joe I
love Joe he's a great guy he came and
said hi the other day okay I gotta keep
going here so so you can see here that
on the Heroku page it's even giving you
some sort of commands that you can
follow we'll worry about that in a
moment but we're missing one other
aspect here the first thing that it's
saying to do is saying Heroku login
meeting login to your Heroku account
from terminal somehow so if I go over
here and I type in Heroku login
it says command not found so one of the
things you need in order to work with
Heroku is a piece of software called the
Heroku toolbelt so I probably should
have pre-installed that but I'm just
going to Google Heroku toolbelt I'm
going to click on the first thing that
comes up and I'm going to download it
and I think it's going to hit this is
going to happen quickly enough that I
can just do this I'm going to install it
continue continue install
password and there we go I'm installing
it I do my stalling dance no III did
like the weird thing about me doing this
dance while this videos gonna have a
preview screen I'm like watching myself
over here as opposed to just dancing to
the camp now it's very weird so I will
edit that out that no one that someone
will make a weird gift out of that or
something okay so now I should be able
to go back and type in Heroku look at
that Oh installing tool I didn't even
know it was gonna do that so maybe you
have to do that I was about to just say
Heroku login but I just was typing
Heroku to make sure it works apparently
I have to do another dance because it's
installing a bunch of stuff oh that was
I don't have to dance okay so now we can
see I should be able to say Heroku log
in and it should ask for my credentials
my account is under my email my password
is I'm logged in so now that I'm logged
in I can actually start to do things
which would allow me to deploy from
terminal here all the stuff for my bot
to Heroku itself so let's go back now to
this page and oh actually this page now
this page sorry and we can see here now
now that I've logged into Heroku the
next thing I need to do is make my bot
into a git repository again the what get
is if you're not familiar with it is out
of the scope of this particular video
but it's a version control software and
what its going to allow me to do is once
I turn it into a git repository meaning
all the code from my bot is in this
folder it's going to allow me to push
that git repository to Heroku because
everything that lives on Heroku is also
a git repository so I'm going to be able
to follow these commands the first thing
I'm going to do is say get in it get in
it and it initialized an empty git
repository yeah if you get if I type got
by the way instead of get it's going to
say got command not found if you get
this error meaning git command not found
this just means you need to download and
install git so if I Google get the very
first thing that comes up is this
particular website
git - SCM calm and I can just somewhere
here right right here I can download for
Mac or for Windows or whatever it is
you're so you can download and install
get and and if for some reason you
didn't have that already ok now that
I've done that the next command that I
need to go to is this Heroku git remote
- hey so what I'm doing is I'm saying I
want my gift repository this thing that
lives on my computer I want it to be
linked to a remote place that remote
place far off in the distance is Heroku
and I not just want to link it to Heroku
but I want to link it to my app that's
coding rainbow demo so I can just take
exactly this here and I can type put
that into terminal I see it over here on
my preview screen and there we go it's
all set now and then I can go here and I
can say the next day okay so the next
set of commands here is now I actually
want to send the stuff to Heroku the way
that you send stuff to Heroku is with a
command a get command called push and
get push me to send pull means receive
so there's a there's a lot there's a lot
to this but our first thing I need to do
is like add and commit and so I'm just
going to follow these commands I someday
this will link to my get tutorials which
will explain all these commands so I'm
going to say git pad
and then I'm just going to use exactly
I'm gonna say commit git commit - a.m.
make it better this I could put my own
comment in here I'm going to say oh you
can't this needs to move like a little
bit over here I'm going to say this is
my bot and it did that and then I'm
going to say get pusher oku master get
push Oroku master which will send it so
now it's sending it to Heroku and it's
going to do all sorts of stuff to try to
run it the thing is I missed some steps
so these would have been the steps if I
had a kind of traditional old-fashioned
web application you know I made some
sort of server it serves up web pages
people log on to my server they see the
web pages but that's not actually what I
made I made this bot which is just this
process that needs to run behind the
scenes with no there's no web server
there's no place there's no URL for
anyone to go do I just want this thing
to run on the server so I have over here
I just want to make sure I get the
syntax right my notes and ok so in order
to do this I'm missing a particular
piece so first thing I want to do
actually by the way I really should have
practiced this advanced but this is fine
so there's so let's here we are we've
kind of we've got ok what have we done
so far we wrote the code for our bot we
pushed it to Heroku and we and it even
just sort of said verifying deploy done
didn't give me any error messages so
let's actually go and look now I'm going
to go back to my dashboard and I should
see here I should be able to find oh
yeah sorry
whoops I should be able to find coding
rainbow demo I'm going to click on that
and we're going to see it says sleeping
so it's not really working it's not
really doing anything yet the reason
it's not doing anything yet is because
it is listed as a web app I need to
change this to be what's called a worker
app and that's what I was talking about
a worker it's a web app is something
that serves up web pages a worker or
something that just works behind the
scenes with its own
process and that's what the bot is so in
order to do that I need to go back to my
code here and I actually need to create
a new file so this is my folder with all
the stuff and I need to create a new
file and I need that file to be called
I'm going to save it a PR OC file proc
file
this is the process file it's a
configuration file that Heroku will look
for to know what is it that this thing
is supposed to do so I'm going to save
that and in that file I'm going to say
this thing is actually a worker not not
a web application and it its job is to
run node bot j/s so I'm going to save
that in there and then I have got to go
back and this is again if you're
unfamiliar with git I here's the thing I
need to I made some changes to my
project now I need those changes to go
on to Heroku those changes are only
locally on my laptop so to do that I
need to say git add dot this is adding
my changes and I need to say commit
which is giving a message to those which
is adding the proc file you can follow
along those community the same things I
did for the first one and then I can say
git push Heroku master this is sending
it to Heroku master Roku is our master
and now that's done it's finished as I
do my little dance I have to wait for
all this to finish launching verifying
deploy etc now I should be able to go
here and hit refresh and I see now I see
look at that it says worker node bot J s
and this I want to turn off I need to
hit edit I want to turn off the web the
web process confirm and I want to turn
on the worker one confirm and now as far
as I know oh my goodness boy we sent a
lot of
weeds you can see now it's you can see
it's running now so it was probably
running I stray interesting that it
actually worked maybe earlier but now it
should be running every 20 seconds it
should post a new tweet and we should be
able to see this by the way if I back
here say Heroku log Oh what I meant log
is not a command perhaps I meant logs
and in fact yes I meant blogs Heroku
logs and you can see by the way this is
running because there's two new tweets
and here it worked right so this is oh
yeah so you can see by the way there's a
bunch of things going on here because I
let it run as a web thing the first time
and the web thing has an error it
stopped but you can see the worker thing
is just saying it worked it worked it
worked so I don't know if 20 seconds has
passed but if I do this again look at
the logs you can see the worker is still
going so I'm actually going to shut it
off because I have it set to like tweet
every 20 seconds which is pretty often
but you can see that this works so now
my bot is deployed on Heroku and by the
way free account free Heroku account to
do this so so you don't this you do not
need a paid Heroku account to simply run
run a nap with a worker process so
hopefully this was helpful to you this
is about 15 minutes of the steps what
I'm going to do in the video's
description is kind of paste links to
all the pieces you need to download off
links all the pieces you need to
download I also have this thing that I
ran through as a written tutorial so I
will post a link to that as well and but
before I go away I'm just going to show
you how I could shut it off if I want to
so I could hit edit here I could turn
this off and hit confirm so now my bot
even though it did for more random
numbers it should have stopped now and
it won't do any more random numbers I've
shut it off right now so that was that
concludes our discussion of how to
deploy your nodejs bot to Heroku over
here