Assignment Chef icon Assignment Chef
All English tutorials

Programming lesson

Building a Zillow-like Zestimate API with Express.js: A Step-by-Step Guide

Learn how to build a JSON API server using Express.js that calculates Zestimates and serves housing data, just like Zillow. This tutorial covers three endpoints for a real-world assignment.

Express.js tutorial Zestimate API Cosc484 assignment 5 Node.js JSON API Express query parameters REST API example Zillow API clone housing data API web development assignment Express.js for beginners API server Node.js real estate API Zestimate formula Express error handling CommonJS require Assignment Chef help

Introduction: Why Build a Zestimate API?

In the world of real estate, Zillow's Zestimate is a household name. It estimates home values using data like square footage, bedrooms, and bathrooms. In this tutorial, you'll build a simplified version of that API using Express.js—a popular Node.js framework. This project is perfect for students in web development courses like Cosc484, and it mirrors real-world API design used by companies like Zillow. By the end, you'll have a working server that handles three endpoints, calculates Zestimates, and filters housing data.

Setting Up Your Express Server

First, ensure you have Node.js installed. Create a file called zillow.js. We'll use CommonJS modules (require) as specified. Install Express via npm: npm install express. Then, set up the basic server:

const express = require('express');
const app = express();
const port = process.argv[2] || 3000;

app.listen(port, () => {
  console.log(`Server running on port ${port}`);
});

This listens on the port provided as the first command-line argument. Next, we'll add middleware to parse query strings (Express does this automatically).

Endpoint 1: /v1/zillow/zestimate

The Zestimate formula is simple: sqft × bed × bath × 10. For example, a 2000 sqft home with 3 beds and 4 baths yields 2000*3*4*10 = 240,000. Here's the handler:

app.get('/v1/zillow/zestimate', (req, res) => {
  const { sqft, bed, bath } = req.query;
  // Convert to integers and validate
  const sqftNum = parseInt(sqft);
  const bedNum = parseInt(bed);
  const bathNum = parseInt(bath);
  if (isNaN(sqftNum) || isNaN(bedNum) || isNaN(bathNum)) {
    return res.status(404).json({ error: 'Invalid parameters' });
  }
  const zestimate = sqftNum * bedNum * bathNum * 10;
  res.json({ zestimate });
});

Test it: /v1/zillow/zestimate?sqft=2000&bed=3&bath=4 returns {"zestimate":240000}. Notice we return 404 for missing or invalid parameters, as per specs.

Endpoint 2: /v1/zillow/houses

This endpoint filters a hardcoded array of houses by city. If no city is given, return an empty array. Use the provided data:

const houses = [
  { price: 240000, city: "baltimore" },
  { price: 300000, city: "austin" },
  { price: 400000, city: "austin" },
  { price: 1000000, city: "seattle"},
  { price: 325000, city: "baltimore" },
  { price: 550000, city: "seattle" },
  { price: 250000, city: "boston" }
];

app.get('/v1/zillow/houses', (req, res) => {
  const { city } = req.query;
  if (!city) {
    return res.json([]);
  }
  const filtered = houses.filter(h => h.city === city.toLowerCase());
  res.json(filtered);
});

Example: /v1/zillow/houses?city=baltimore returns two houses. Unknown cities return [].

Endpoint 3: /v1/zillow/prices

This endpoint requires a usd parameter and returns houses with price ≤ usd. If missing, return 404.

app.get('/v1/zillow/prices', (req, res) => {
  const { usd } = req.query;
  if (!usd || isNaN(parseInt(usd))) {
    return res.status(404).json([]);
  }
  const maxPrice = parseInt(usd);
  const result = houses.filter(h => h.price <= maxPrice);
  res.json(result);
});

For /v1/zillow/prices?usd=300000, you get houses under $300k. If none, [].

Error Handling and Status Codes

Always return 200 for successful requests and 404 for invalid endpoints or missing/incorrect parameters. For any undefined route, add a catch-all:

app.use((req, res) => {
  res.status(404).json({ error: 'Not found' });
});

Testing Your API

Run node zillow.js 8080 and test with a browser or curl. Example curl commands:

  • curl "http://localhost:8080/v1/zillow/zestimate?sqft=1500&bed=3&bath=2"
  • curl "http://localhost:8080/v1/zillow/houses?city=austin"
  • curl "http://localhost:8080/v1/zillow/prices?usd=500000"

Real-World Connection: Zillow and AI

Zillow's Zestimate uses machine learning, but this assignment teaches the API layer. In 2026, AI tools like ChatGPT and real estate apps rely on such APIs. Understanding Express.js and RESTful design is crucial for modern web development, whether you're building a housing API or a gaming leaderboard.

Common Pitfalls

  • Using http module instead of Express: this will result in a 0 grade.
  • Using ES6 imports (import) instead of CommonJS require: 10% penalty.
  • Not validating query parameters: always check for NaN or missing values.

Conclusion

You've built a functional Zestimate API with three endpoints. This project simulates real-world tasks at companies like Zillow. Practice by adding more endpoints or connecting to a database. For assignment help, Assignment Chef offers tutoring on Express.js and Node.js.