Spaces:
No application file
No application file
Shamik Das commited on
Upload 5 files
Browse filesFiles changed (5)
- .gitignoreAdded+36
- index.htmlAdded+711
- package-lock.jsonAdded+911
- package.jsonAdded+15
- server.jsAdded+40
123456789101112131415161718192021222324252627282930313233343536# Dependencies
node_modules/
# Env secrets
.env
.env.*
!.env.example
# Logs
logs/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Builds and caches
dist/
build/
out/
.cache/
.parcel-cache/
.tmp/
.temp/
coverage/
# Editors/OS
.vscode/
.idea/
.DS_Store
Thumbs.db
desktop.ini
# Hosting configs
.netlify/
.vercel/123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Climora - Weather App</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
animation: {
'pulse-slow': 'pulse 3s ease-in-out infinite',
'float': 'float 6s ease-in-out infinite',
'bounce-slow': 'bounce 3s infinite',
'fade-in': 'fadeIn 0.5s ease-in-out',
'slide-up': 'slideUp 0.7s ease-out',
'slide-down': 'slideDown 0.7s ease-out',
'spin-slow': 'spin 3s linear infinite' // added to fix animate-spin-slow
},
keyframes: {
float: {
'0%, 100%': { transform: 'translateY(0)' },
'50%': { transform: 'translateY(-10px)' }
},
fadeIn: {
'0%': { opacity: '0' },
'100%': { opacity: '1' }
},
slideUp: {
'0%': { transform: 'translateY(20px)', opacity: '0' },
'100%': { transform: 'translateY(0)', opacity: '1' }
},
slideDown: {
'0%': { transform: 'translateY(-20px)', opacity: '0' },
'100%': { transform: 'translateY(0)', opacity: '1' }
}
},
backdropBlur: {
xs: '2px',
}
}
}
}
</script>
<style type="text/tailwindcss">
@layer utilities {
.glass {
background-color: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(4px);
border: 1px solid rgba(255, 255, 255, 0.3);
}
.text-shadow { text-shadow: 0 2px 4px rgba(0,0,0,0.1); }
/* Animated gradient background */
@keyframes gradientMove {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
.bg-animated { background-size: 300% 300%; animation: gradientMove 18s ease infinite; }
.dark .glass { background-color: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.2); }
/* Text visibility and swap animations */
.text-glow { text-shadow: 0 2px 10px rgba(0,0,0,0.25), 0 1px 2px rgba(0,0,0,0.2); }
@keyframes textOut { to { opacity: 0; transform: translateY(-6px); } }
@keyframes textIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.swap-out { animation: textOut 180ms ease forwards; will-change: transform, opacity; }
.swap-in { animation: textIn 220ms ease forwards; will-change: transform, opacity; }
@keyframes pop { 0% { transform: scale(0.9); opacity: .7; } 60% { transform: scale(1.06); opacity: 1; } 100% { transform: scale(1); } }
.pop-once { animation: pop 220ms ease both; }
/* Sky decor animations */
@keyframes driftX {
0% { transform: translateX(-20vw); }
100% { transform: translateX(120vw); }
}
@keyframes bob {
0%,100% { transform: translateY(0); }
50% { transform: translateY(-12px); }
}
@keyframes twinkle {
0%, 100% { opacity: .2; }
50% { opacity: 1; }
}
@keyframes cloudDrift {
0% { transform: translateX(-30vw); }
100% { transform: translateX(130vw); }
}
.orb-path {
position: absolute;
top: 14vh;
left: -20vw;
animation: driftX 55s linear infinite;
}
#moon-wrap { top: 18vh; animation-duration: 65s; }
.sun-orb, .moon-orb {
width: clamp(80px, 12vw, 160px);
height: clamp(80px, 12vw, 160px);
border-radius: 9999px;
will-change: transform, filter, opacity;
animation: bob 6s ease-in-out infinite;
filter: drop-shadow(0 0 18px rgba(255,255,255,0.35));
}
.sun-orb {
background: radial-gradient(circle at 30% 30%, #fff8b0 0%, #fde047 35%, #f59e0b 60%, rgba(245, 158, 11, 0) 70%);
box-shadow: 0 0 60px 20px rgba(253, 224, 71, 0.25);
}
.moon-orb {
background: radial-gradient(circle at 35% 35%, #ffffff 0%, #e5e7eb 40%, #cbd5e1 70%, rgba(203,213,225,0) 75%);
box-shadow: 0 0 60px 18px rgba(148,163,184,0.22);
}
.star {
position: absolute;
width: 2px; height: 2px;
border-radius: 9999px;
background: rgba(255,255,255,0.9);
box-shadow: 0 0 6px rgba(255,255,255,0.7);
animation: twinkle var(--twinkle, 2.2s) ease-in-out infinite;
will-change: opacity;
}
.cloud {
position: absolute;
height: 90px;
border-radius: 9999px;
background: rgba(255,255,255,0.28);
filter: blur(2px);
box-shadow:
40px 10px 0 10px rgba(255,255,255,0.28),
90px 0px 0 16px rgba(255,255,255,0.24),
140px 15px 0 12px rgba(255,255,255,0.22);
animation: cloudDrift var(--speed, 60s) linear infinite;
will-change: transform, opacity;
}
}
</style>
</head>
<body class="min-h-screen bg-gradient-to-br from-blue-400 via-purple-500 to-pink-500 flex flex-col items-center justify-center p-4 transition-all duration-1000">
<!-- Animated Sky Layer -->
<div id="sky" class="pointer-events-none fixed inset-0 z-0 overflow-hidden">
<!-- Day/Night orbs -->
<div id="sun-wrap" class="orb-path opacity-0 transition-opacity duration-700">
<div id="sun" class="sun-orb"></div>
</div>
<div id="moon-wrap" class="orb-path opacity-0 transition-opacity duration-700">
<div id="moon" class="moon-orb"></div>
</div>
<!-- Stars and clouds -->
<div id="sky-stars" class="absolute inset-0 opacity-0 transition-opacity duration-700"></div>
<div id="clouds" class="absolute inset-x-0 top-8 h-44 opacity-0 transition-opacity duration-700"></div>
</div>
<div class="w-full max-w-md mx-auto relative z-10">
<!-- Dark Mode Toggle -->
<button id="theme-toggle" class="fixed top-4 right-4 glass rounded-full p-3 text-white hover:bg-white/30 transition-all duration-300" aria-label="Toggle dark mode" title="Toggle dark mode">
<i id="theme-toggle-icon" class="fas fa-moon"></i>
<span class="sr-only">Toggle dark mode</span>
</button>
<!-- App Header with Animation -->
<header class="text-center mb-8 animate-slide-down">
<h1 class="text-5xl font-bold text-white mb-2 text-shadow text-glow">Climora</h1>
<p class="text-white/80 text-lg text-glow">Real-time Weather</p>
</header>
<!-- Search Form -->
<form class="mb-6 animate-slide-up">
<div class="flex flex-col sm:flex-row gap-3">
<div class="relative flex-1">
<input
type="text"
id="city-input"
placeholder="Enter city name"
class="w-full px-5 py-4 rounded-2xl glass text-white placeholder-white/70 focus:outline-none focus:ring-2 focus:ring-white/50 transition-all duration-300"
/>
<i class="fas fa-search absolute right-4 top-1/2 transform -translate-y-1/2 text-white/70"></i>
</div>
<button
type="submit"
id="search-btn"
class="px-6 py-4 glass text-white rounded-2xl hover:bg-white/30 transition-all duration-300 font-medium flex items-center justify-center gap-2"
>
<i class="fas fa-search"></i>
<span>Search</span>
</button>
</div>
<div class="mt-4 flex justify-center">
<button
type="button"
id="location-btn"
class="flex items-center gap-3 px-6 py-4 glass text-white rounded-2xl hover:bg-white/30 transition-all duration-300 font-medium animate-pulse-slow"
>
<i class="fas fa-location-arrow"></i>
Use My Location
</button>
</div>
</form>
<!-- Loading Animation -->
<div id="loading" class="hidden flex-col items-center justify-center py-12">
<div class="relative w-20 h-20 mb-6">
<div class="absolute inset-0 border-4 border-white/30 border-t-white rounded-full animate-spin"></div>
<div class="absolute inset-2 border-4 border-white/20 border-b-white rounded-full animate-spin-slow"></div>
</div>
<p class="text-white/80 text-lg">Fetching weather data...</p>
</div>
<!-- Error Message -->
<div id="error-message" class="hidden bg-red-500/20 backdrop-blur-xs border border-red-500/30 text-white p-4 rounded-2xl mb-6 animate-fade-in">
<div class="flex items-center gap-3">
<i class="fas fa-exclamation-circle text-xl"></i>
<p id="error-text">City not found. Please try again.</p>
</div>
</div>
<!-- Weather Card -->
<div id="weather-card" class="glass rounded-3xl p-6 shadow-2xl transition-all duration-500 animate-fade-in">
<div class="flex justify-between items-start mb-6">
<div>
<h2 id="city-name" class="text-2xl font-bold text-white text-shadow text-glow">Kolkata, IN</h2>
<p id="weather-condition" class="text-white/80 capitalize">Loading...</p>
</div>
<div id="weather-icon" class="text-white text-5xl animate-float">
<i class="fas fa-cloud-sun"></i>
</div>
</div>
<div class="flex items-center justify-center mb-8">
<div id="temperature" class="text-7xl font-bold text-white text-shadow animate-pulse-slow text-glow">22°C</div>
</div>
<div class="grid grid-cols-2 gap-4">
<div class="bg-white/10 backdrop-blur-xs rounded-xl p-4 text-center transition-transform duration-300 hover:scale-105">
<p class="text-white/70 text-sm mb-1">Feels Like</p>
<p id="feels-like" class="text-white font-semibold text-xl">24°C</p>
</div>
<div class="bg-white/10 backdrop-blur-xs rounded-xl p-4 text-center transition-transform duration-300 hover:scale-105">
<p class="text-white/70 text-sm mb-1">Humidity</p>
<p id="humidity" class="text-white font-semibold text-xl">65%</p>
</div>
<div class="bg-white/10 backdrop-blur-xs rounded-xl p-4 text-center transition-transform duration-300 hover:scale-105">
<p class="text-white/70 text-sm mb-1">Wind Speed</p>
<p id="wind-speed" class="text-white font-semibold text-xl">12 km/h</p>
</div>
<div class="bg-white/10 backdrop-blur-xs rounded-xl p-4 text-center transition-transform duration-300 hover:scale-105">
<p class="text-white/70 text-sm mb-1">Pressure</p>
<p id="pressure" class="text-white font-semibold text-xl">1015 hPa</p>
</div>
</div>
</div>
<!-- Footer -->
<footer class="mt-8 text-center text-white/70 animate-fade-in">
<p>
Built with ❤ by
<a
href="https://www.linkedin.com/in/shamik-das-379347359"
target="_blank"
rel="noopener noreferrer"
class="no-underline text-amber-200 dark:text-amber-300 hover:text-white/90 transition-colors duration-200 text-glow font-medium focus:outline-none focus-visible:ring-2 focus-visible:ring-white/60 rounded-md"
title="View LinkedIn profile"
>Shamik Das</a>
</p>
</footer>
</div>
<script>
// API proxy to keep the key secret on the server
const API_PROXY = '/api/weather';
let currentCondition = 'Partly Cloudy';
let isDayMode = true;
// DOM Elements
const cityInput = document.getElementById('city-input');
const searchBtn = document.getElementById('search-btn');
const locationBtn = document.getElementById('location-btn');
const themeToggleBtn = document.getElementById('theme-toggle');
const themeToggleIcon = document.getElementById('theme-toggle-icon');
const loading = document.getElementById('loading');
const errorMessage = document.getElementById('error-message');
const errorText = document.getElementById('error-text');
const weatherCard = document.getElementById('weather-card');
const cityName = document.getElementById('city-name');
const weatherCondition = document.getElementById('weather-condition');
const weatherIcon = document.getElementById('weather-icon');
const temperature = document.getElementById('temperature');
const feelsLike = document.getElementById('feels-like');
const humidity = document.getElementById('humidity');
const windSpeed = document.getElementById('wind-speed');
const pressure = document.getElementById('pressure');
const body = document.body;
const form = document.querySelector('form');
const sky = document.getElementById('sky');
const sunWrap = document.getElementById('sun-wrap');
const moonWrap = document.getElementById('moon-wrap');
const starsEl = document.getElementById('sky-stars');
const cloudsEl = document.getElementById('clouds');
// Mock weather data for demonstration
const mockWeatherData = {
'new york': {
city: 'New York',
country: 'US',
temp: 22,
condition: 'Partly Cloudy',
icon: 'fa-cloud-sun',
feels_like: 24,
humidity: 65,
wind_speed: 12,
pressure: 1015,
background: 'from-blue-400 via-purple-500 to-pink-500'
},
'london': {
city: 'London',
country: 'UK',
temp: 15,
condition: 'Rainy',
icon: 'fa-cloud-rain',
feels_like: 14,
humidity: 80,
wind_speed: 18,
pressure: 1005,
background: 'from-blue-500 to-indigo-700'
},
'tokyo': {
city: 'Tokyo',
country: 'Japan',
temp: 28,
condition: 'Sunny',
icon: 'fa-sun',
feels_like: 30,
humidity: 55,
wind_speed: 8,
pressure: 1012,
background: 'from-yellow-400 to-orange-500'
},
'sydney': {
city: 'Sydney',
country: 'Australia',
temp: 25,
condition: 'Cloudy',
icon: 'fa-cloud',
feels_like: 26,
humidity: 70,
wind_speed: 14,
pressure: 1018,
background: 'from-gray-400 to-gray-600'
},
'paris': {
city: 'Paris',
country: 'France',
temp: 18,
condition: 'Clear',
icon: 'fa-sun',
feels_like: 17,
humidity: 60,
wind_speed: 10,
pressure: 1013,
background: 'from-yellow-300 to-orange-400'
}
};
// Weather gradients (light and dark)
const weatherGradientsLight = {
'Clear': 'from-yellow-300 via-orange-400 to-pink-500',
'Sunny': 'from-yellow-300 via-orange-400 to-pink-500',
'Clouds': 'from-slate-300 via-slate-400 to-slate-500',
'Cloudy': 'from-slate-300 via-slate-400 to-slate-500',
'Partly Cloudy': 'from-blue-300 via-purple-400 to-pink-500',
'Rain': 'from-indigo-500 via-blue-600 to-slate-700',
'Rainy': 'from-indigo-500 via-blue-600 to-slate-700',
'Drizzle': 'from-blue-400 via-indigo-500 to-slate-600',
'Thunderstorm': 'from-purple-700 via-indigo-800 to-gray-900',
'Snow': 'from-blue-300 via-blue-400 to-blue-500', // darker for contrast
'Mist': 'from-gray-400 via-gray-500 to-gray-600', // better contrast
'Fog': 'from-gray-400 via-gray-500 to-gray-600' // better contrast
};
const weatherGradientsDark = {
'Clear': 'from-amber-400 via-orange-600 to-rose-700',
'Sunny': 'from-amber-400 via-orange-600 to-rose-700',
'Clouds': 'from-slate-700 via-slate-800 to-slate-900',
'Cloudy': 'from-slate-700 via-slate-800 to-slate-900',
'Partly Cloudy': 'from-indigo-700 via-purple-800 to-slate-900',
'Rain': 'from-blue-900 via-indigo-900 to-slate-900',
'Rainy': 'from-blue-900 via-indigo-900 to-slate-900',
'Drizzle': 'from-slate-800 via-blue-900 to-slate-950',
'Thunderstorm': 'from-purple-900 via-indigo-950 to-black',
'Snow': 'from-slate-600 via-slate-700 to-slate-800', // keep dark in dark mode
'Mist': 'from-slate-600 via-slate-700 to-slate-800',
'Fog': 'from-slate-600 via-slate-700 to-slate-800'
};
function isDark() {
return document.documentElement.classList.contains('dark');
}
function updateThemeToggleIcon(mode) {
if ((mode || (isDark() ? 'dark' : 'light')) === 'dark') {
themeToggleIcon.classList.remove('fa-moon');
themeToggleIcon.classList.add('fa-sun');
} else {
themeToggleIcon.classList.remove('fa-sun');
themeToggleIcon.classList.add('fa-moon');
}
}
function applyBackgroundGradient(condition) {
const map = isDark() ? weatherGradientsDark : weatherGradientsLight;
const gradient = map[condition] || (isDark() ? 'from-slate-700 via-slate-800 to-slate-900' : 'from-blue-400 via-purple-500 to-pink-500');
body.className = `min-h-screen bg-gradient-to-br ${gradient} bg-animated flex flex-col items-center justify-center p-4 transition-all duration-1000`;
}
function setTheme(mode) {
const m = mode || (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
document.documentElement.classList.toggle('dark', m === 'dark');
localStorage.setItem('theme', m);
updateThemeToggleIcon(m);
applyBackgroundGradient(currentCondition);
}
// Determine day/night from API response
function determineIsDay(apiData) {
try {
const sunrise = apiData?.sys?.sunrise;
const sunset = apiData?.sys?.sunset;
const dt = apiData?.dt;
if (sunrise && sunset && dt) {
return dt >= sunrise && dt < sunset;
}
// Fallback using timezone offset if needed
const tz = apiData?.timezone ?? 0;
const nowUtc = Math.floor(Date.now() / 1000);
const localTs = nowUtc + tz;
const hours = (new Date(localTs * 1000)).getUTCHours();
return hours >= 6 && hours < 18;
} catch {
return true;
}
}
// Build starfield once
function createStars(count = 80) {
if (starsEl.childElementCount > 0) return;
const frag = document.createDocumentFragment();
for (let i = 0; i < count; i++) {
const s = document.createElement('span');
s.className = 'star';
const left = Math.random() * 100;
const top = Math.random() * 100;
const size = Math.random() * 2 + 1;
s.style.left = `${left}vw`;
s.style.top = `${top}vh`;
s.style.width = `${size}px`;
s.style.height = `${size}px`;
s.style.setProperty('--twinkle', `${1.8 + Math.random()*2.4}s`);
s.style.animationDelay = `${Math.random() * 2}s`;
frag.appendChild(s);
}
starsEl.appendChild(frag);
}
// Build a few clouds for daytime
function createClouds(count = 4) {
if (cloudsEl.childElementCount > 0) return;
for (let i = 0; i < count; i++) {
const c = document.createElement('div');
c.className = 'cloud';
const width = 180 + Math.random()*180; // 180-360px
const top = 5 + Math.random()*60; // 5-65vh
const delay = Math.random()*-40; // negative to desync
const speed = 50 + Math.random()*30; // 50-80s
c.style.width = `${width}px`;
c.style.top = `${top}vh`;
c.style.left = `${-30 - Math.random()*30}vw`;
c.style.setProperty('--speed', `${speed}s`);
c.style.animationDelay = `${delay}s`;
cloudsEl.appendChild(c);
}
}
// Toggle sky based on day/night
function updateDayNight(day) {
isDayMode = !!day;
// Sun / Moon visibility
sunWrap.classList.toggle('opacity-100', isDayMode);
sunWrap.classList.toggle('opacity-0', !isDayMode);
moonWrap.classList.toggle('opacity-100', !isDayMode);
moonWrap.classList.toggle('opacity-0', isDayMode);
// Stars and clouds
starsEl.classList.toggle('opacity-60', !isDayMode);
starsEl.classList.toggle('opacity-0', isDayMode);
cloudsEl.classList.toggle('opacity-35', isDayMode);
cloudsEl.classList.toggle('opacity-0', !isDayMode);
}
// Show loading animation
function showLoading() {
loading.classList.remove('hidden');
weatherCard.classList.add('hidden');
errorMessage.classList.add('hidden');
}
// Hide loading animation
function hideLoading() {
loading.classList.add('hidden');
}
// Show error message
function showError(message) {
errorText.textContent = message;
errorMessage.classList.remove('hidden');
weatherCard.classList.add('hidden');
hideLoading();
}
// Hide error message
function hideError() {
errorMessage.classList.add('hidden');
}
// Smooth text swaps
function swapText(el, newText) {
if (el.textContent === newText) return;
el.classList.remove('swap-in');
el.classList.add('swap-out');
el.addEventListener('animationend', function handler() {
el.removeEventListener('animationend', handler);
el.textContent = newText;
el.classList.remove('swap-out');
el.classList.add('swap-in');
// clean up swap-in after it plays
setTimeout(() => el.classList.remove('swap-in'), 260);
}, { once: true });
}
// Count-up/down number animation
function animateNumber(el, to, suffix = '') {
const currentText = el.textContent || '';
const match = currentText.match(/-?\d+/);
const from = match ? parseInt(match[0], 10) : 0;
const start = performance.now();
const duration = 500;
const end = typeof to === 'number' ? to : parseFloat(to);
if (from === end || isNaN(end)) {
el.textContent = `${end}${suffix}`;
return;
}
function frame(now) {
const t = Math.min(1, (now - start) / duration);
const eased = t < 0.5 ? 2*t*t : -1 + (4 - 2*t)*t; // easeInOutQuad
const val = Math.round(from + (end - from) * eased);
el.textContent = `${val}${suffix}`;
if (t < 1) requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
}
// Update weather display
function updateWeather(data) {
swapText(cityName, `${data.city}, ${data.country}`);
swapText(weatherCondition, data.condition);
animateNumber(temperature, data.temp, '°C');
animateNumber(feelsLike, data.feels_like, '°C');
animateNumber(humidity, data.humidity, '%');
animateNumber(windSpeed, data.wind_speed, ' km/h');
animateNumber(pressure, data.pressure, ' hPa');
// Update weather icon with animation
weatherIcon.innerHTML = `<i class="fas ${data.icon}"></i>`;
weatherIcon.classList.remove('pop-once');
// trigger reflow to restart animation
void weatherIcon.offsetWidth;
weatherIcon.classList.add('pop-once');
// Update background gradient (animated, theme-aware)
currentCondition = data.condition;
applyBackgroundGradient(currentCondition);
// Show weather card with animation
weatherCard.classList.remove('hidden');
weatherCard.classList.add('animate-fade-in');
hideLoading();
hideError();
}
// Fetch weather from OpenWeatherMap API
async function fetchWeather(city) {
showLoading();
try {
const response = await fetch(`${API_PROXY}?q=${encodeURIComponent(city)}`);
if (!response.ok) throw new Error('City not found');
const data = await response.json();
// Day/Night by location time
updateDayNight(determineIsDay(data));
const weatherData = {
city: data.name,
country: data.sys.country,
temp: Math.round(data.main.temp),
condition: data.weather[0].main,
icon: getWeatherIcon(data.weather[0].main),
feels_like: Math.round(data.main.feels_like),
humidity: data.main.humidity,
wind_speed: Math.round(data.wind.speed * 3.6), // m/s -> km/h
pressure: data.main.pressure
};
updateWeather(weatherData);
} catch (error) {
showError('City not found. Please try again.');
}
}
// Get weather icon based on condition
function getWeatherIcon(condition) {
const iconMap = {
'Clear': 'fa-sun',
'Clouds': 'fa-cloud',
'Rain': 'fa-cloud-rain',
'Drizzle': 'fa-cloud-rain',
'Thunderstorm': 'fa-bolt',
'Snow': 'fa-snowflake',
'Mist': 'fa-smog',
'Fog': 'fa-smog',
'Partly Cloudy': 'fa-cloud-sun',
'Sunny': 'fa-sun'
};
return iconMap[condition] || 'fa-cloud';
}
// Geolocation success callback
function handleLocationSuccess(position) {
const { latitude, longitude } = position.coords;
fetchWeatherByCoordinates(latitude, longitude);
}
// Geolocation error callback
function handleLocationError() {
showError('Unable to retrieve your location. Please enter a city.');
}
// Fetch weather by coordinates
async function fetchWeatherByCoordinates(lat, lon) {
showLoading();
try {
const response = await fetch(`${API_PROXY}?lat=${lat}&lon=${lon}`);
if (!response.ok) throw new Error('Unable to fetch weather data');
const data = await response.json();
// Day/Night by location time
updateDayNight(determineIsDay(data));
const weatherData = {
city: data.name,
country: data.sys.country,
temp: Math.round(data.main.temp),
condition: data.weather[0].main,
icon: getWeatherIcon(data.weather[0].main),
feels_like: Math.round(data.main.feels_like),
humidity: data.main.humidity,
wind_speed: Math.round(data.wind.speed * 3.6), // m/s -> km/h
pressure: data.main.pressure
};
updateWeather(weatherData);
} catch (error) {
showError('Unable to fetch weather data. Please try again later.');
}
}
// Event Listeners
form.addEventListener('submit', (e) => {
e.preventDefault();
const city = cityInput.value.trim();
if (city) {
fetchWeather(city);
} else {
showError('Please enter a city name');
}
});
locationBtn.addEventListener('click', () => {
if (navigator.geolocation) {
showLoading();
navigator.geolocation.getCurrentPosition(
handleLocationSuccess,
handleLocationError,
{ timeout: 10000 }
);
} else {
showError('Geolocation is not supported by this browser');
}
});
// Theme toggle
themeToggleBtn.addEventListener('click', () => {
const next = isDark() ? 'light' : 'dark';
setTheme(next);
});
// Initialize with default weather
document.addEventListener('DOMContentLoaded', () => {
const stored = localStorage.getItem('theme');
setTheme(stored || null);
updateThemeToggleIcon();
// Build sky decor once
createStars(80);
createClouds(4);
// Default guess by local time until first API call
const h = new Date().getHours();
updateDayNight(h >= 6 && h < 18);
fetchWeather('Kolkata, IN');
});
</script>
</body>
</html>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911{
"name": "climora",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "climora",
"version": "1.0.0",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"node-fetch": "^2.6.12"
}
},
"node_modules/accepts": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
"integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
"license": "MIT",
"dependencies": {
"mime-types": "~2.1.34",
"negotiator": "0.6.3"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==",
"license": "MIT"
},
"node_modules/body-parser": {
"version": "1.20.3",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.3.tgz",
"integrity": "sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==",
"license": "MIT",
"dependencies": {
"bytes": "3.1.2",
"content-type": "~1.0.5",
"debug": "2.6.9",
"depd": "2.0.0",
"destroy": "1.2.0",
"http-errors": "2.0.0",
"iconv-lite": "0.4.24",
"on-finished": "2.4.1",
"qs": "6.13.0",
"raw-body": "2.5.2",
"type-is": "~1.6.18",
"unpipe": "1.0.0"
},
"engines": {
"node": ">= 0.8",
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/bytes": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/call-bound": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"get-intrinsic": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/content-disposition": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
"integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
"license": "MIT",
"dependencies": {
"safe-buffer": "5.2.1"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/content-type": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/cookie": {
"version": "0.7.1",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz",
"integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/cookie-signature": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==",
"license": "MIT"
},
"node_modules/cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"license": "MIT",
"dependencies": {
"object-assign": "^4",
"vary": "^1"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"license": "MIT",
"dependencies": {
"ms": "2.0.0"
}
},
"node_modules/depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/destroy": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
"license": "MIT",
"engines": {
"node": ">= 0.8",
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/dotenv": {
"version": "16.6.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.6.1.tgz",
"integrity": "sha512-uBq4egWHTcTt33a72vpSG0z3HnPuIl6NqYcTrKEg2azoEyl2hpW0zqlxysq2pK9HlDIHyHyakeYaYnSAwd8bow==",
"license": "BSD-2-Clause",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.1",
"es-errors": "^1.3.0",
"gopd": "^1.2.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
"license": "MIT"
},
"node_modules/encodeurl": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
"integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/es-define-property": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-errors": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-object-atoms": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/escape-html": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
"license": "MIT"
},
"node_modules/etag": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/express": {
"version": "4.21.2",
"resolved": "https://registry.npmjs.org/express/-/express-4.21.2.tgz",
"integrity": "sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==",
"license": "MIT",
"dependencies": {
"accepts": "~1.3.8",
"array-flatten": "1.1.1",
"body-parser": "1.20.3",
"content-disposition": "0.5.4",
"content-type": "~1.0.4",
"cookie": "0.7.1",
"cookie-signature": "1.0.6",
"debug": "2.6.9",
"depd": "2.0.0",
"encodeurl": "~2.0.0",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"finalhandler": "1.3.1",
"fresh": "0.5.2",
"http-errors": "2.0.0",
"merge-descriptors": "1.0.3",
"methods": "~1.1.2",
"on-finished": "2.4.1",
"parseurl": "~1.3.3",
"path-to-regexp": "0.1.12",
"proxy-addr": "~2.0.7",
"qs": "6.13.0",
"range-parser": "~1.2.1",
"safe-buffer": "5.2.1",
"send": "0.19.0",
"serve-static": "1.16.2",
"setprototypeof": "1.2.0",
"statuses": "2.0.1",
"type-is": "~1.6.18",
"utils-merge": "1.0.1",
"vary": "~1.1.2"
},
"engines": {
"node": ">= 0.10.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/finalhandler": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.1.tgz",
"integrity": "sha512-6BN9trH7bp3qvnrRyzsBz+g3lZxTNZTbVO2EV1CS0WIcDbawYVdYvGflME/9QP0h0pYlCDBCTjYa9nZzMDpyxQ==",
"license": "MIT",
"dependencies": {
"debug": "2.6.9",
"encodeurl": "~2.0.0",
"escape-html": "~1.0.3",
"on-finished": "2.4.1",
"parseurl": "~1.3.3",
"statuses": "2.0.1",
"unpipe": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/fresh": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
"integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/function-bind": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-intrinsic": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.1.1",
"function-bind": "^1.1.2",
"get-proto": "^1.0.1",
"gopd": "^1.2.0",
"has-symbols": "^1.1.0",
"hasown": "^2.0.2",
"math-intrinsics": "^1.1.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
"license": "MIT",
"dependencies": {
"dunder-proto": "^1.0.1",
"es-object-atoms": "^1.0.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/gopd": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-symbols": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/hasown": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
"license": "MIT",
"dependencies": {
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/http-errors": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
"integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==",
"license": "MIT",
"dependencies": {
"depd": "2.0.0",
"inherits": "2.0.4",
"setprototypeof": "1.2.0",
"statuses": "2.0.1",
"toidentifier": "1.0.1"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"license": "ISC"
},
"node_modules/ipaddr.js": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
"license": "MIT",
"engines": {
"node": ">= 0.10"
}
},
"node_modules/math-intrinsics": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/merge-descriptors": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz",
"integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/methods": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
"integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
"license": "MIT",
"bin": {
"mime": "cli.js"
},
"engines": {
"node": ">=4"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"license": "MIT",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
"license": "MIT"
},
"node_modules/negotiator": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
"integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/node-fetch": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
"integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
"license": "MIT",
"dependencies": {
"whatwg-url": "^5.0.0"
},
"engines": {
"node": "4.x || >=6.0.0"
},
"peerDependencies": {
"encoding": "^0.1.0"
},
"peerDependenciesMeta": {
"encoding": {
"optional": true
}
}
},
"node_modules/object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/object-inspect": {
"version": "1.13.4",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
"integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/on-finished": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
"license": "MIT",
"dependencies": {
"ee-first": "1.1.1"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/parseurl": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/path-to-regexp": {
"version": "0.1.12",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz",
"integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==",
"license": "MIT"
},
"node_modules/proxy-addr": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
"license": "MIT",
"dependencies": {
"forwarded": "0.2.0",
"ipaddr.js": "1.9.1"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/qs": {
"version": "6.13.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz",
"integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==",
"license": "BSD-3-Clause",
"dependencies": {
"side-channel": "^1.0.6"
},
"engines": {
"node": ">=0.6"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/range-parser": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/raw-body": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz",
"integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
"license": "MIT",
"dependencies": {
"bytes": "3.1.2",
"http-errors": "2.0.0",
"iconv-lite": "0.4.24",
"unpipe": "1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
},
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"license": "MIT"
},
"node_modules/send": {
"version": "0.19.0",
"resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz",
"integrity": "sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==",
"license": "MIT",
"dependencies": {
"debug": "2.6.9",
"depd": "2.0.0",
"destroy": "1.2.0",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"fresh": "0.5.2",
"http-errors": "2.0.0",
"mime": "1.6.0",
"ms": "2.1.3",
"on-finished": "2.4.1",
"range-parser": "~1.2.1",
"statuses": "2.0.1"
},
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/send/node_modules/encodeurl": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
"integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/send/node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"license": "MIT"
},
"node_modules/serve-static": {
"version": "1.16.2",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.2.tgz",
"integrity": "sha512-VqpjJZKadQB/PEbEwvFdO43Ax5dFBZ2UECszz8bQ7pi7wt//PWe1P6MN7eCnjsatYtBT6EuiClbjSWP2WrIoTw==",
"license": "MIT",
"dependencies": {
"encodeurl": "~2.0.0",
"escape-html": "~1.0.3",
"parseurl": "~1.3.3",
"send": "0.19.0"
},
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/setprototypeof": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
"license": "ISC"
},
"node_modules/side-channel": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz",
"integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"object-inspect": "^1.13.3",
"side-channel-list": "^1.0.0",
"side-channel-map": "^1.0.1",
"side-channel-weakmap": "^1.0.2"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-list": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz",
"integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"object-inspect": "^1.13.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-map": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz",
"integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-weakmap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
"integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3",
"side-channel-map": "^1.0.1"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/statuses": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
"integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/toidentifier": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
"license": "MIT",
"engines": {
"node": ">=0.6"
}
},
"node_modules/tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==",
"license": "MIT"
},
"node_modules/type-is": {
"version": "1.6.18",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
"license": "MIT",
"dependencies": {
"media-typer": "0.3.0",
"mime-types": "~2.1.24"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
"integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
"license": "MIT",
"engines": {
"node": ">= 0.4.0"
}
},
"node_modules/vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
"license": "BSD-2-Clause"
},
"node_modules/whatwg-url": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
"license": "MIT",
"dependencies": {
"tr46": "~0.0.3",
"webidl-conversions": "^3.0.0"
}
}
}
}123456789101112131415{
"name": "climora",
"version": "1.0.0",
"main": "server.js",
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
},
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"node-fetch": "^2.6.12"
}
}12345678910111213141516171819202122232425262728293031323334353637383940const express = require('express');
const fetch = require('node-fetch');
const cors = require('cors');
const path = require('path');
require('dotenv').config();
const API_BASE = 'https://api.openweathermap.org/data/2.5';
const API_KEY = process.env.OPENWEATHER_API_KEY;
if (!API_KEY) {
console.error('Missing OPENWEATHER_API_KEY in .env');
process.exit(1);
}
const app = express();
app.use(cors());
app.use(express.static(path.join(__dirname)));
app.get('/api/weather', async (req, res) => {
try {
const { q, lat, lon } = req.query;
if (!q && !(lat && lon)) {
return res.status(400).json({ error: 'q or lat+lon required' });
}
const params = q
? `q=${encodeURIComponent(q)}`
: `lat=${encodeURIComponent(lat)}&lon=${encodeURIComponent(lon)}`;
const url = `${API_BASE}/weather?${params}&appid=${API_KEY}&units=metric`;
const r = await fetch(url);
const data = await r.json();
res.status(r.status).json(data);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Server error' });
}
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Server listening on ${PORT}`));.gitignoreAdded+36
index.htmlAdded+711
package-lock.jsonAdded+911
package.jsonAdded+15
server.jsAdded+40