Demo project, showing the use of Svelte, TypeScript, and Express to build a weather forecast web app, powered by the AccuWeather API
This is a demo full-stack web application, which uses the AccuWeather API to power a multi-day forecast, with selectable location.
It uses Svelte, TypeScript, HTML, CSS, and other web technologies.
There are a few values that are configurable for the backend and frontend.
Configuration for the backend can be done through either:
set port=3002 && npm run serve
/backend/.env.example.json
to /backend/.env.json
and filling in the values🚨 In order to run this app you MUST provide a valid value for
accuWeatherKey
(which should be your API key), through either of the above methods.
For the full list of values you can configure for the backend, refer to the example .env.json
file.
For the front-end, the only real configuration value is BACKEND_BASE
, which can be used to decouple the serving of the API from the static files (see "Static Serving" section for details).
Although you can cd
to either /backend
or /frontend
and run each part of the app individually from its directory, all commands are exposed through the root package.json
of this project for convenience.
From the root directory, here is a sample workflow for if you just cloned this repository:
npm install
:postinstall
hook)npm run dev
npm run build
npm run serve
npm run build
is a pre-requisite to this command - serve
is expecting that there is already build output ready to serve or execute.npm run start
, which runs build
and then serve
accuWeatherKey
. See "Configuration" for details.Many commands also have optional suffixes if you don't want to work on both parts of the app at the same time. For example, you can use
npm run dev:backend
instead ofnpm run dev
, if you just want to work on the API without touching the frontend.
This is a mono-repo, which contains both the frontend, backend, and commands to run both.
package.json
are specific to DigitalOcean deployment settingsBy default, this project will serve both the API and the frontend from the same Express server. However, I also made it configurable so that you can decouple them easily.
To decouple, before running build:frontend
, set an environmental variable for BACKEND_BASE
to point to the hosted Express endpoint. Then run build:frontend
, and after it finishes, you can now take the optimized /dist
and serve anywhere that lets you serve static files; Netlify, various CDNs, shared hosting, etc.
The "automatic location" feature, based on IP address, uses AccuWeather's IP-to-geolocation service, which doesn't always return the most accurate results. To counter this, users are asked whether or not the "guessed" location is good enough for them, or if they would like to manually select a location, before forecasting data is fetched.
Responsive
If I had more time to work on this, here are the things I would focus on as top priority: