Instructor: Here I have a simple HTML file. I can deploy this directly to Now as long as I have the CLI installed simply by typing Now.
As you can see, that deployment worked and the URL has been copied to the clipboard. If we head to the browser, paste in that URL, everything's working as it should be.
During that deployment, you probably noticed the warning saying that we haven't created a now.json file and specified the version. Let's fix that. We're using version two of Now. Let's save that and we'll deploy again.
As you can see, this time there was no errors. If we go back to the browser, we can paste in that URL again and everything's still working.
Next, let's say we want to create a simple Node API. We can do that by creating a new folder called Node. In there, we'll create a file called index.js.
This file exports a single function which gets access to the request and response objects. Finally, it sends a response of the current time string.
For this to work correctly, we need to tell Now how to handle this file. We do that in the now.json by specifying a builds array. The builds array contains objects which describe how we want Now to serve and parse these files.
We'll start by telling Now how to serve our HTML files. Each object should contain a source key and also a use key. For HTML files, we want to use the static build pack.
Next, we need to tell it how to run this Node file. To do that we'll pass another object, tell it where it can find our Node files, and then we also need to tell it which build pack to use. Let's add a link to this in our HTML file. Finally, we'll deploy again.
The deployment was successful, so let's head over to the browser. We will paste in the URL, which is automatically copied to the clipboard. We can see now that we have this link to the time from Node, and there it is.
Let's take this one step further again by adding another endpoint. This time, we will use Go. I'll create a new file called index.go. I'm going to paste the function in here, which does the same thing as our Node function. It just tells the time.
Then, if we switch over to our HTML file, we can add a link to this Go endpoint. That obviously serves from /go. We'll change this reference from Node to Go as well.
Finally, let's run Now one last time and deploy everything. If we take a look at the browser, paste in the URL, we have both the links we need. We can get the time from the Node endpoint, or we can get the time from the Go endpoint.