To provide real-time weather data, you need to handle API integration, error handling and automatic scaling. With Vercel functions and Express, you can build a production-ready weather API in minutes.
In this tutorial, you will build and deploy a weather API route using the Open-Meteo API that:
- Accepts a city name and geocodes it to coordinates
- Fetches current weather data from the Open-Meteo API
- Returns temperature, humidity, wind speed, and other weather metrics with optional metric/imperial unit conversion
- Node.js and pnpm installed locally
- A Vercel account
- Basic understanding of Express and async/await in TypeScript
Start with the Express starter template. Once your the project is deployed on Vercel, clone the repository locally.
You can also create the project locally using the Vercel CLI with the following command
Add the weather endpoint after your existing routes:
Install the dependencies and launch the application in dev mode:
Use curl to test the API route:
- Push the changes to your remote repository or run the
vercelcli command - Vercel will create a new preview deployment for your to test
- Merge to main branch to deploy to Production
When you deploy an Express app to Vercel, the application becomes a single Vercel Function and uses Fluid compute by default.
In this tutorial, you’ve built a real-time weather API using Express on Vercel.
You learned to:
- Structure a dynamic API route and integrate external APIs
- Deploy the app to Vercel as a function for automatic scaling
For a production application, make sure that you use a weather API that will not be rate limited based on the amount of traffic that you are expecting.