Deploy a Monorepo to Now V2

Paul McBride
InstructorPaul McBride
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 3 years ago

Now by Zeit has recently been updated and now supports multi-language monorepos. In this lesson we'll build and deploy a simple app with an API powered by Node.js and Go.

If you want to follow along with this lesson, you will need to install now-cli.

Instructor: [00:00] 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.

[00:09] 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.

[00:20] 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.

[00:49] 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.

[00:59] 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.

[01:12] 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.

[01:22] 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.

[01:42] 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.

[02:00] 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.

[02:26] 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.

[02:40] 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.

[02:58] Next, let's tell Now how to serve this Go directory. I'm going to copy this object, and we will change all the references from Node in JavaScript to Go. Of course, the build pack is now/go.

[03:12] 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.

[03:24] 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.

egghead
egghead
~ a minute ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today