Hosting a Server on Render

What Is Render?

Render is a hosting service: a company that runs your code on their computers, all day, at a public URL anyone can visit. It has a free tier, and that's all we'll use in this class.

You should not spend any money on Render. Always pick the Free instance type, and don't add a credit card or any payment method. Without one, Render can't charge you: if you ever go over the free limits, it just pauses your service until next month.

Static Hosting vs. Running a Server

GitHub Pages has been hosting our sites all semester. It's a static host: when a browser asks for a file, GitHub sends that file back exactly as it is. It never runs any of our code itself.

A Node server is different. It's a program that has to keep running somewhere, waiting for requests and deciding what to send back. GitHub Pages can't do that. Render (like Heroku, Railway, or Fly.io, which you may have heard of) gives you a computer that runs your server for you, using the commands you tell it to.

Step 1: Make a Server and Push It

  1. Make a folder
    In VS Code, open your csc336-fall2026 folder. Make a new folder inside it called render-test.
  2. Make server.js
    Inside render-test, make a file called server.js with this code. It uses only Node's built-in http, so there's nothing to install.
    import http from "http";
    
    // Render tells our server which port to use with the PORT environment variable.
    // On your own computer, PORT isn't set, so we use 3000 instead.
    let port = process.env.PORT || 3000;
    
    // This function runs once for every request that comes in.
    let server = http.createServer((req, res) => {
        // On Render, this shows up in the Logs page (Render's version of the terminal).
        console.log(req.method + " " + req.url);
    
        // This runs fresh for every request, so the time changes every time you refresh.
        // A static host like GitHub Pages can't do this: it only sends files.
        let now = new Date();
    
        res.writeHead(200, { "Content-Type": "text/plain" });
        res.end("Hello from my server! The server's clock says " + now.toString());
    });
    
    server.listen(port, () => {
        console.log("Server running on port " + port);
    });
  3. Make package.json
    Also inside render-test, make a file called package.json:
    {
      "name": "render-test",
      "type": "module"
    }
    "type": "module" is what lets us use import. Render also needs this file to exist, or its npm install step will fail.
  4. Test it on your computer first
    In the terminal:
    cd render-test
    node server.js
    Visit http://localhost:3000. You should see the hello message, and the time should change when you refresh. Press Ctrl+C to stop the server.
  5. Commit and push
    Commit both files and push them to GitHub, the same way you've pushed every assignment. Check on github.com that the render-test folder is there with both files in it.

Step 2: Make a Render Account

  1. Go to render.com and click Get Started (or Sign Up).
  2. Sign up with your GitHub account or with an email address. Either one works.
  3. If it asks you about a plan, choose the free one (Hobby). Skip anything that asks for payment information.
  4. Once you're logged in, you'll land on the Dashboard. This is where all your services live.

Step 3: Create a Web Service

  1. In the Dashboard, click New (top of the page), then Web Service.
  2. Point it at your repo. Render asks where your code is. Choose the Public Git Repository tab, and paste in your repo's URL:
    https://github.com/YOUR-GITHUB-USERNAME/csc336-fall2026
    Then click Connect. This works because your repo is public. (The other option, Git Provider, links your GitHub account to Render. That works too, but you don't need it.)
  3. Fill in the settings. Render shows a form. Here's what to put in each field:
    Field What to put
    Name Anything, like yourname-render-test. It becomes part of your URL.
    Language Node
    Branch main
    Region Anything (the default is fine)
    Root Directory render-test (see below)
    Build Command npm install
    Start Command node server.js
    Instance Type Free
  4. About Root Directory: your repo has a lot of things in it (your homepage, your assignments), but the server is only the render-test folder. Root Directory tells Render "treat this folder as the whole project." Render runs the build and start commands inside that folder, which is why the start command is just node server.js and not node render-test/server.js. If your server is in a different folder, put that folder's path here instead (for example a08/server). If you leave it blank, Render uses the top of your repo. You can change it later in your service's Settings page, under Build & Deploy.
  5. Build Command runs once, to set things up: npm install downloads whatever is listed in package.json (nothing yet, but once you use Express, this is what installs it). Start Command is what actually runs your server, exactly like typing it in your own terminal.
  6. Click Deploy Web Service at the bottom.

Step 4: Watch It Deploy and Get Your Link

  1. Render shows you a log while it works. "Deploying" means: download your code from GitHub, run your build command, then run your start command. The first one can take a few minutes.
  2. Near the end you should see your own console.log message, Server running on port 10000, and then a message saying your service is live. (10000 is the port Render picked and put in process.env.PORT.)
  3. Your link is at the top of your service's page, right under its name. It looks like this:
    https://yourname-render-test.onrender.com
    Click it. You should see your hello message, coming from your server, running on Render's computer. Refresh it a few times and watch the time change.
  4. Click Logs in the left sidebar. Every time you refresh, a new GET / line shows up. This is your server's terminal now.
  5. Compare with GitHub Pages. Visit https://YOUR-GITHUB-USERNAME.github.io/csc336-fall2026/render-test/server.js. GitHub Pages just shows you the file's text. The time never changes, because nothing ran it.

Changing Your Server Later

Because we connected with a public repo URL, Render doesn't notice when you push new code. After you commit and push a change, go to your service's page in Render and click Manual Deploy, then Deploy latest commit.

Things to Know About the Free Tier

If Something Goes Wrong

Check the deploy log first. The error is usually near the bottom.

You see It probably means
Could not read package.json Root Directory is wrong, or package.json wasn't pushed
Cannot find module .../server.js Start Command or Root Directory doesn't match where server.js is (check spelling and capitalization)
Cannot use import statement outside a module package.json is missing "type": "module"
Your latest change isn't showing up Did you push it? Then click Manual Deploy
The page takes forever to load It was asleep. Give it a minute