- JavaScript 67.6%
- CSS 19%
- HTML 13.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| docs | ||
| public | ||
| server | ||
| .env.example | ||
| .gitignore | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
Vejrklar
A Danish weather and clothing app built for a web-development assignment. The frontend uses HTML, CSS and vanilla JavaScript; the backend uses Node.js, Express and SQLite. The app starts with Kolding; users can search for another city or request their device's location.
Guests can view weather and generic adult clothing advice. Registered users can save favourite cities, an age group and clothing preferences on the server, then receive personalised recommendations.
The dashboard includes a three-day overview for København, Aarhus, Odense, Aalborg, Esbjerg, Kolding, Vejle and Roskilde. Select a city for current conditions, clothing recommendations with SVG icons and explanations, a three-day forecast and a timeline in three-hour steps. Search is in the top-right header on desktop and wraps below the brand on smaller screens.
The theme toggle switches between dark and light mode, saves the choice in local storage, and defaults to the system theme on first visit. Weather and clothing data remain on the Node server; local storage only holds the theme choice.
Design: Designbrief på dansk · Editable Figma file · Design notes and font limitations.
Run locally
Requires Node.js 22.9 or newer, npm and an OpenWeather API key.
- Run
npm installin this folder. - On first setup, copy
.env.exampleto.env. Preserve an existing.envfile. - Get your own API key from OpenWeather. The key needs access to Current Weather, 5 Day / 3 Hour Forecast and Geocoding.
- Set
OPENWEATHER_API_KEY=your_key_herein.env. - Run
npm run devand open http://localhost:3000.
Use npm start to run without automatic restarts. After changing .env, stop the process with Ctrl+C and start it again. If port 3000 is occupied, change PORT in .env.
The page works through the Node server; do not open index.html directly or use Live Server. Without a configured API key, the app displays a setup error rather than made-up weather.
| Command | Purpose |
|---|---|
npm run dev |
Start and restart when imported server files change |
npm start |
Start without automatic restarts |
Refresh the browser after frontend changes. Change PORT in .env if 3000 is occupied.
Using the app
- Select a city card, search in the header or click Brug min position.
- Read current conditions and the explanation for each clothing item.
- Select a forecast day to see advice for that day's conditions. Selecting a city or clicking Opdatér vejret loads current-weather advice again.
- Open Log ind / Opret, then Opret konto. Registration signs you in automatically.
- Open Min profil, change your preferences and click Gem præferencer to update the advice.
- Click Gem som favorit in a city's heading. Saved cities appear above the Denmark overview; select or remove them there.
- Log out to return to generic advice. Log back in to retrieve saved preferences and favourites.
Structure
public/
index.html Page structure and accessible status messages
css/style.css Responsive styles
js/app.js Weather, forecast, account and favourite interactions
js/theme.js Apply saved/system theme before rendering
server/
index.js Start the localhost server
app.js API route and static frontend hosting
weather.js OpenWeather request and response mapping
clothing.js Generic and personalised clothing rules
accounts.js SQLite accounts, sessions, profile and favourite routes
data/ Private SQLite database (created automatically; ignored by Git)
docs/design.md Figma link, screen inventory and design notes
.env.example Environment variable template
Request flow
Browser → GET /api/weather → Express → OpenWeather → Express → browser.
flowchart LR
Browser[HTML / CSS / JavaScript] -->|Same-origin API requests| Server[Node.js / Express]
Server -->|Key stays on server| Weather[OpenWeather]
Server -->|Accounts and preferences| Database[(SQLite)]
Server --> Rules[Clothing rules]
Rules -->|Explained suggestions| Server
Server -->|JSON responses| Browser
The browser never receives the API key. The server requests metric units and Danish descriptions. It returns temperature (°C), feels-like temperature (°C), wind (m/s), humidity (%), rain over the previous hour (mm), an icon code, and the observation timestamp. Rain is a past-hour amount, not a forecast. Times use the selected location's UTC offset supplied by OpenWeather.
City search and geolocation
GET /api/locations?q=Londonuses OpenWeather's direct geocoding API and returns up to five matches with name, region, country and coordinates. Choose a match to see its weather. There is no automatic selection of the first result.GET /api/weather?lat=51.5&lon=-0.1fetches weather at selected coordinates. Both coordinates are required and validated when either is provided. Without coordinates, the endpoint defaults to Kolding.- “Brug min position” calls
navigator.geolocation.getCurrentPositiononly after a click. Permission denial, unavailable location and timeout each display a helpful message. City search remains available. - Geolocation works on localhost or HTTPS. For a deployed site, HTTPS is required. Device coordinates are sent to the Node server and OpenWeather to fetch weather. They are not persisted automatically; clicking “Gem som favorit” explicitly stores the selected location in your account.
- Refresh keeps the currently displayed location. If a weather request fails, the last successful weather remains visible with its original observation time and an error message.
Both frontend and API share one origin, so no CORS configuration is needed. .env is ignored by Git; only public/ is served as static files.
Forecast and clothing data
GET /api/forecast?lat=55.49&lon=9.47uses OpenWeather's five-day/three-hour endpoint. It returns forecast slots and summaries for the first three available local dates, including today when available. Without coordinates it defaults to Kolding.GET /api/citiesreturns forecasts for all eight Danish cities. A failed city includes an error while other cities remain available. The page offers a retry button.- Successful weather and forecast responses are cached in memory for ten minutes. Concurrent identical requests share one upstream request. Errors are not cached, and restarting the server clears the cache. Clicking refresh re-reads the server cache; it does not bypass it. The app does not poll automatically.
- Daily minimum and maximum temperatures use all available three-hour temperature points. The icon and description use the point nearest local noon. These are summaries of forecast points, not observed daily extremes. Incomplete days are labelled “Delvis dag”.
- Daily precipitation probability is the highest probability among the day's forecast points, rather than an independently calculated whole-day probability. Wind is the highest predicted speed among the points.
- Current clothing advice uses current feels-like temperature, wind and recent rain. Select a forecast day to use the lowest predicted feels-like temperature, highest wind and precipitation probability, and total forecast precipitation for its available periods.
- Clothing rules use temperature bands below 5, 12 and 18 °C, a precipitation probability threshold of 40% (or any predicted precipitation), and a wind threshold of 8 m/s. Guests get generic adult suggestions. Signed-in users get the personalisation described below.
Accounts and personalisation
Click Log ind / Opret in the header. Registration asks for name, email, password (10–128 characters) and age group. Successful registration signs you in. Open Min profil to update your name, age group and clothing preferences. Logging in retrieves the saved profile and favourites from the server; reloading the page restores the session. Logging out returns to generic recommendations.
Use Gem som favorit in the city detail heading to save the selected city. Saved cities appear above the Denmark overview. Click one to load its details, or use its remove button. Each account can store up to 20 cities; favourite IDs are scoped to the signed-in account.
Preferences are applied on the server to current weather and each forecast day's clothing advice:
- Temperature sensitivity: “Jeg fryser let” chooses clothing as if it were 3 °C colder; “Jeg får let det varmt” chooses clothing as if it were 3 °C warmer. The explanation still states the actual feels-like temperature.
- Shorts are only suggested in warm weather when explicitly allowed.
- A preferred umbrella replaces the waterproof outer-layer suggestion in wet weather with wind below 8 m/s. Stronger wind keeps the waterproof layer and explains why.
- Child profiles get an extra-layer suggestion in cool weather. Other age groups use the baseline rules and their chosen preferences.
- A snowsuit is only suggested as an alternative in cold weather when explicitly allowed, regardless of age group.
Accounts, preferences, favourites and sessions are stored in data/vejrklar.sqlite using SQLite. This directory is outside the public frontend and is ignored by Git. No database setup or account service is required. Back up the entire data directory while the server is stopped if you need to preserve accounts when moving the project.
Passwords use Node's asynchronous scrypt with a unique random salt; only the hash is stored. Random session tokens use HTTP-only, SameSite=Lax cookies, expire after seven days, and are stored as hashes in SQLite. Login rotates the current session; logout invalidates it. JSON-only account mutations reject cross-origin requests, SQL uses bound parameters, and registration/login requests are rate-limited. Shared upstream weather caching stores weather only; profile-based recommendations are generated separately per request.
API reference
Account mutations require JSON. Protected routes identify the user from the session cookie rather than accepting a client-supplied user ID.
| Method | Route | Purpose | Login required |
|---|---|---|---|
| GET | /api/weather |
Current weather and clothing; optional lat and lon |
No |
| GET | /api/forecast |
Daily summaries, forecast points and day-specific clothing; optional lat and lon |
No |
| GET | /api/cities |
Forecasts for eight Danish cities | No |
| GET | /api/locations?q=London |
Matching cities | No |
| GET | /api/account/me |
Profile/favourites or { "user": null } |
No |
| POST | /api/account/register |
Create account and session | No |
| POST | /api/account/login |
Authenticate and start a session | No |
| POST | /api/account/logout |
Invalidate current session | No |
| PUT | /api/account/profile |
Save name, age group and preferences | Yes |
| POST | /api/account/favourites |
Save a city's name, country and coordinates | Yes |
| DELETE | /api/account/favourites/:id |
Remove an owned favourite | Yes |
Registration accepts name, email, password, ageGroup and preferences. Profile updates accept name, ageGroup and preferences. Age groups are child, teen, adult and senior. Preferences contain sensitivity (cold, normal, warm), rainProtection (raincoat, umbrella), allowShorts and allowSnowsuit (booleans).
SQLite uses three tables: users, sessions and favourites. User rows contain the name, unique email, password hash/salt, age group and JSON preferences. Sessions and favourites reference their owner.