API Design in Node.js, v5

Deploying to Render

Scott Moss
Netflix
API Design in Node.js, v5

Lesson Description

The "Deploying to Render" Lesson is part of the full, API Design in Node.js, v5 course featured in this preview video. Here's what you'd learn in this lesson:

Scott walks through deploying to the course project to Render by creating a web service, setting environment variables, deploying, and testing the app.

Preview
Close

Transcript from the "Deploying to Render" Lesson

[00:00:00]
>> Speaker 1: Now that we're there, all we need to do is follow these directions on how to deploy Node.js Express I decided to link to it versus writing it here because if they change it, you can just click on it to get the latest

[00:00:00]
If I put whatever they put in here, it might be dead tomorrow if they change their docs So I decided to keep that live, and honestly, I think it's funny because the docs are just this

[00:00:00]
This is just the docs It's just this, that's it There's really nothing else That's the documentation It's just, Go here and click this button I was like, oh, that's actually kind of easy, so that's what we're going to do: go there and click the button, but first, I need to push up my branch to GitHub that I'm going to deploy, which is just going to be this life lesson branch

[00:00:00]
I'm going to do that I have my migrations I'll say, Origin live lesson 13 Boom, OK, that is good to go I'm now going to go to Render I already have an account But it takes like 2 seconds to make an account

[00:00:00]
Just sign in with GitHub and make an account You don't have to put any credit card, you don't have to do anything It's super simple Then what you're going to do is make a new web service

[00:00:00]
That's the thing you want to make, not a static site, not a background worker, it's a web service Let's make a new web service It immediately brings me to my GitHub This is why I signed in with GitHub because it automatically has my GitHub

[00:00:00]
I have Node.js right here I'm going to pull that up Cool, I actually deployed this already, so I'll put a one next to it because I already have a version of this deployed here

[00:00:00]
I'm going to call this Habit API The thing is this is a globally unique name, so it's not just unique to my project or my account, it's for their whole platform It's globally unique because they want to give you a pretty URL

[00:00:00]
Heroku did the same thing So I don't know if somebody has this or not I'll call it Habit API, hopefully nobody took it If you were going to do a bunch of different things together like a background job, a cron, a web service, some database, you can add all of them to a project, but we're not doing that

[00:00:00]
Language is Node.js, branch is live lesson 13, the one I just pushed up I'll keep it on the West Coast Route directory is source The only thing I'm going to change here is I'm going to change npm install

[00:00:00]
I'm sure Yarn will work fine, but we haven't tested it with Yarn this whole time and I don't want that to go wrong It already looked at my package.json and saw that there was a start command and chose to use that as the start command, so it already inferred that

[00:00:00]
I'll pick free, and then I'm going to add my environment variables First, I'll add my database URL Then I'll add another environment variable I know I need a JWT secret

[00:00:00]
I'm going to copy the one from localhost It's just a 32-character string I don't feel like typing a new one I'll set the app stage to production I'll ensure NODE_ENV is set to production as well

[00:00:00]
I'll add bcrypt rounds, setting it to 8 You can also just drop a whole .env file in here if you want I have a /health route that's sending back a status The health check will look for a 200 status code

[00:00:00]
Pre-deployed command would be great for running migrations, but you have to pay for that Auto deploy will be on commit Now it's going to build, installing packages, uploading files, and deploying

[00:00:00]
If there are any configuration issues, I can go back and adjust the environment variables The deployment looks successful I can check the health endpoint, register a user, and confirm everything is working

[00:00:00]
Whenever we push to this branch, Render will redeploy Ideally, you'd set up different environments like staging, and maybe each team member gets their own environment

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now