Marcy Lab School Docs
  • Welcome
  • Student Guidelines & Policies
    • Student Handbook
    • AI Policy
    • Academic Calendar
  • Environment Setup
    • Local Environment Setup - Mac
    • Local Environment Setup - Windows
    • GitHub Setup
    • Postgres Setup
  • How-Tos
    • How To Code at Marcy: Code Style Guide
    • How to Do Short Response and Coding Assignments
    • How to Debug
    • How to PEDAC
    • How to Create A GitHub Organization and Scrumboard
    • How to Create Projects with Vite
    • How to Deploy on GitHub Pages
    • How to Deploy on Render
    • How to Test your API with Postman
  • Mod 0 - Command Line Interfaces, Git, and GitHub
    • Overview
    • 1. Command Line Interfaces
    • 2. Git & GitHub
    • 3. Git Pulling & Merging
    • 4. Git Branching & PRs
  • Mod 1 - JavaScript Fundamentals
    • Overview
    • 1. Intro to Programming
    • 2. Errors
    • 3. Node & Node Modules
    • 4. Variables, Functions & String Methods
    • 5. Control Flow, typeof, and Math
    • 6. Loops
    • 7. Arrays
    • 8. Objects
    • 9. Higher Order Functions: Callbacks
    • 10. Higher Order Functions: Array Methods
    • 11. Regex
  • Mod 2 - HTML, CSS & the DOM
    • Overview
    • 1. HTML
    • 2. CSS
    • 3. Accessibility (a11y)
    • 4. The Document Object Model (DOM) API
    • 5. Events
    • 6. Forms
    • 7. The Box Model and Positioning
    • 8. Flexbox
    • 9. Grid & Media Queries
    • 10. ESModules
    • 11. Vite
    • 12. LocalStorage
  • Mod 3 - Async & APIs
    • Overview
    • 1. Promises
    • 2. Fetch
    • 3. Building a Fetching App
    • 4. Async & Await
    • 5. A Generic Fetch Handler
  • Mod 4 - Project Week!
    • Important How Tos and Guides
      • How to Create a GitHub Organization and Scrum Board
      • How To Start a Project with Vite
      • How To Deploy a Project with GitHub Pages
    • Project Week Overview
    • Agile Methodologies
    • Deliverables & Milestones
    • Technical Requirements Checklist
    • Free API List
    • Collaborative GitHub
  • Mod 5 - Object-Oriented Programming
    • Overview
    • 1. Intro to OOP, Encapsulation, Factory Functions, and Closure
    • 2. Classes
    • 3. Private & Static
    • 4. UML Diagrams & Has Many/Belongs To Relationships
    • 5. Challenge: Implementing Has Many/Belongs To
    • 6. Inheritance
    • 7. Polymorphism
    • 8. Review and Practice
    • MDN: Object Prototypes
  • Mod 6 - Data Structures & Algorithms
    • Overview
    • Important How Tos and Guides
      • How to Debug
      • How to PEDAC
    • 1. Nodes & Linked Lists
    • 2. Singly & Doubly Linked Lists
    • 3. Stacks & Queues
    • 4. Recursion
    • 5. Trees
  • Mod 7 - React
    • Overview
    • Important How Tos and Guides
      • How to Create Projects with Vite
      • How to Deploy on GitHub Pages
    • 1. Intro to React
    • 2. Events, State, and Forms
    • 3. Fetching with useEffect
    • 4. React Router
    • 5. Building a Flashcards App
    • 6. React Context
    • 7. Global Context Pattern
  • Mod 8 - Backend
    • Overview
    • Important How Tos and Guides
      • How to Deploy on Render
      • How to Test your API with Postman
      • Postgres Setup
    • 1. Intro to Express
    • 2. Building a Static Web Server with Middleware
    • 3. Securing API Keys and Environment Variables
    • 4. RESTful CRUD API
    • 5. Model-View-Controller Architecture
    • 6. SQL and Databases
    • 7. JOIN (Association) SQL Queries
    • 8. Knex
    • 9. Your First Fullstack App!
    • 10. Migrations & Seeds
    • 11. Schema Design & Normalization
    • 12. Hashing Passwords with Bcrypt
    • 13. React Express Auth Template Overview
  • Mod 9 - Civic Tech Hackathon
    • Overview
    • Rubric
  • Mod 10 - Capstone
    • Overview
Powered by GitBook
On this page
  • Overview
  • Render vs. Github Pages
  • Create An Account
  • Deploy A Server
  • What Do the Build and Start Commands Do?
  • Deploy A Database
  • Future changes to your code
  1. How-Tos

How to Deploy on Render

PreviousHow to Deploy on GitHub PagesNextHow to Test your API with Postman

Last updated 9 days ago

Table of Contents:

Overview

Render vs. Github Pages

  • Github Pages provides static site hosting.

    • This means that the server that Github Pages runs on your behalf can only send static files to the client (HTML, CSS, and JS files).

    • Github Pages static sites are not capable of receiving or sending messages via HTTP.

  • Render provides web service and database hosting (it can also host static sites).

    • This means that the server that Render runs on your behalf can send static assets, receive and send messages via HTTP, and interact with a database.

    • Render also can host your database giving you a one-stop-shop for running your fullstack application.

Create An Account

Start by creating an account using your GitHub account. This will let you easily deploy straight from a GitHub repository.

This will take you to your Dashboard where you can see existing deployments.

Deploy A Server

  1. Make sure you are signed in using your GitHub account

  2. https://dashboard.render.com/ and click on New +

  3. Select Web Service

  4. Choose Git Provider to find a repository on your account. It may take some time for your repositories to load.

    • If your repository is public, you can provide a link to the repository but it will not be able to auto-deploy on future commits. As such, this is NOT the preferred method.

  5. Fill out the information for your Server

    • Name - the name of your app (it will appear in the URL that render gives you. For example: app-name-here.onrender.com)

    • Language - Node

    • Branch - draft for assignments, main for portfolio projects

    • Region - select US East (Ohio)

    • Root Directory - Leave blank (will default to the root of your repo)

    • Build Command:

      • If your application has a database, see the next section

      • If your application has a Vite frontend:

        cd [vite_folder_name] && npm i && npm run build && cd ../server && npm i
      • If neither:

        cd server && npm i
    • Start Command (assuming your index.js file is in server/):

      cd server && node index.js
    • Instance Type - select Free

  6. Add Any environment variables your application may need:

  7. Select Deploy Web Service

This should take you to your web service's dashboard where you can see the latest build information and the URL. In a few minutes your server will be up and running!

Any time that you want to make an update to your deployed server, just commit and push the change to your repo! The deployment process will automatically run your "Build" and "Start" commands (unless you used a public git URL to setup your server in which cause auto-deployments are disabled).

What Do the Build and Start Commands Do?

The "Build" and "Start" commands are executed before every new deploy as a part of the "Auto Deploy" process. The server will re-deploy your application on every new commit.

Projects built using Vite cannot be served as they are stored in the repository. They need to have static assets created via the npm run build command. Those static assets are then stored in the dist/ folder and served by our server. In the event that we change the frontend in a new commit, we want to rebuild those assets before restarting the server. Therefore, the "Build" command above is executed every time the server is deployed for a new commit (even when the frontend doesn't change).

After the "Build" command runs, the "Start" command runs to start the server. To ensure that our server works properly, we just need to make sure the server dependencies are installed and then run the index.js file with node:

As a result, the "continuous deployment" process would look like this:

  1. A commit is made with changes to the project

  2. Render detects the commit and begins a new deployment

  3. The "build" command is executed, generating updated static assets

  4. The "start" command is executed, starting the server

  5. The deployment completes and the server is live!

Deploy A Database

  1. Make sure you have an account on https://render.com/ and that you sign in using Github

  2. Create a Postgres Server

    • https://dashboard.render.com/ and click on New +

    • Select PostgreSQL

    • Fill out information for your DB (leave all other fields blank)

      • Name - the name of your application

      • Region - select US East (Ohio)

      • Instance Type - select Free

    • Select Create Database

    • Keep the created database page open. You will need the Internal Database URL value from this page for step 4. This URL will look follow this pattern:

      postgresql://user:password@host/dbname
  3. Deploy Your Express Server. Follow the instructions above for deploying a server with the following changes:

    • Build command: Okay this part is going to be a bit wonky because we are going to be using a Free instance type which means we don't have access to a "Pre-Deploy Command"

      • The very first time that you deploy your server, use the following as your build command to set up migrations, seeds, and build the frontend:

        cd frontend && npm i && npm run build && cd ../server && npm i && npm run migrate:rollback && npm run migrate && npm run seed
      • Immediately after the first deploy is successful, go back into your settings and change this build command to the following (we're removing the migrate:rollback, migrate, and seed portions as these will wipe your database!):

        cd frontend && npm i && npm run build && cd ../server && npm i
    • Add your environment variables:

      • Add a PG_CONNECTION_STRING variable. Its value should be the Internal Database URL value from step 2e above.

      • Add a NODE_ENV variable set to production

      • Your values should look like this: (No quotations needed!)

        SESSION_SECRET=AS12FD42FKJ42FIE3WOIWEUR1283
        PG_CONNECTION_STRING=postgresql://user:password@host/dbname
        NODE_ENV=production
  4. Click Save Changes

Future changes to your code

If you followed these steps, your Render server will redeploy whenever the main branch is committed to. To update the deployed application, simply commit to main.

Add a SESSION_SECRET variable and a long, random value. It can literally be just a random jumble of characters. You can also use to generate a random key.

https://randomkeygen.com/
Overview
Render vs. Github Pages
Create An Account
Deploy A Server
What Do the Build and Start Commands Do?
Deploy A Database
Future changes to your code
create an account using GitHub
The Render Dashboard
Add environment variables individually or paste multiple values at a time from a .env file.
alt text
If your project had a vite-project folder for the frontend, and a server folder for the backend, your configuration would look like this