Welcome to this beginner-friendly tutorial! In this guide, you'll learn how to build Climatic, a weather dashboard that integrates Node.js and Python using MetaCall. You'll see how to install MetaCall, write Python functions for weather analytics, call them from Node.js, and deploy everything to the cloud.
MetaCall allows you to execute functions across multiple programming languages within the same project. Let’s install it first!
Open your terminal and run:
curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | shAfter installation, check if MetaCall is installed correctly by running:
metacall --versionFor more details, visit the MetaCall Installer.
Climatic is a polyglot weather dashboard that combines different programming languages to provide weather insights. Here's how it works:
- Node.js Backend: Handles API requests and serves data.
- Python Analytics Module: Processes weather data for analysis.
- MetaCall Integration: Runs Python functions directly inside Node.js.
- Vue.js Frontend (Optional): Displays weather data in a user-friendly UI.
JavaScript is great for APIs, but it lacks powerful data analysis libraries like pandas and NumPy. That’s why we use Python to process the data while keeping the API logic in Node.js.
Before writing any code, let's install the necessary libraries.
Run the following command in your project folder:
npm install express metacall axiosFor weather data analysis, install these Python packages:
pip install pandas numpy requestsNow, we are ready to write some code! 🚀
We'll write a simple Python function to analyze temperature data using pandas.
import pandas as pd
def analyze_weather(data):
df = pd.DataFrame(data)
return df.describe().to_dict()- This function takes a list of temperature readings and returns statistical summaries (like min, max, and average temperature).
Now, let’s integrate our Python function into a Node.js server!
const { metacall } = require('metacall');
async function analyzeWeather(data) {
await metacall.load('weather_analysis.py');
const result = await metacall.call('analyze_weather', data);
console.log("Weather Analysis Result:", result);
}
analyzeWeather([{ temperature: 20 }, { temperature: 25 }, { temperature: 30 }]);✅ Loads the Python file using metacall.load().
✅ Calls the analyze_weather function with sample data.
✅ Prints the result in the terminal.
Run the script to test it:
node server.jsYou should see the analyzed weather data printed to the console! 🎉
Instead of using static data, let’s fetch real-time weather data from OpenWeatherMap.
- Sign up at OpenWeatherMap.
- Get your API key from the dashboard.
Modify server.js to retrieve weather data:
const axios = require('axios');
async function fetchWeather(city) {
const API_KEY = 'YOUR_OPENWEATHERMAP_API_KEY';
const url = `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${API_KEY}&units=metric`;
const response = await axios.get(url);
return response.data;
}
fetchWeather('London').then(console.log);Now, running node server.js will print live weather data for London. 🌍
Before deploying, let’s ensure our function works with MetaCall locally.
Run the following command:
metacall weather_analysis.pyThis verifies that MetaCall can execute our function without errors.
Now, let's deploy our Python function to the MetaCall Cloud so it can be used anywhere!
Go to MetaCall Dashboard and log in or sign up.
- Navigate to the Deployments section.
- Click Upload Function and select
weather_analysis.py.
- MetaCall will generate a public API URL for your function.
- Copy this URL to use it in your Node.js backend.
Replace the local MetaCall call with an HTTP request to your cloud function:
const axios = require('axios');
async function analyzeWeather(data) {
const response = await axios.post('YOUR_METACALL_API_URL', { args: [data] });
console.log("Weather Analysis Result:", response.data);
}
analyzeWeather([{ temperature: 20 }, { temperature: 25 }, { temperature: 30 }]);node server.jsNow, your Node.js backend is using a cloud-based Python function! 🚀
Congratulations! You’ve successfully built a polyglot weather dashboard that:
✅ Uses Python for analytics and Node.js for API handling ✅ Calls Python functions inside Node.js using MetaCall ✅ Fetches live weather data from OpenWeatherMap ✅ Runs locally and on the MetaCall Cloud (FaaS)
Now, you can expand it by:
- Adding a Vue.js frontend to display weather data.
- Enhancing Python functions for better weather predictions.
Let me know if you have any questions! 🚀