Node.js prototype template, using the GOV.UK Prototype Kit and
the GOV.UK Frontend.
Basically the
GOV.UK Prototype KitandGOV.UK Frontendwrapped up and provided on the Core Delivery Platform
- Requirements
- GOV.UK Prototype Kit and GOV.UK Frontend
- Using the refreshed GOV.UK brand
- Setting a password
- Setting multiple passwords
- Removing the need for a password
- Npm scripts
- Updating dependencies
- Environment Variables and Secrets
- Creating a secret
- aqie-back-end service
- Docker
- Licence
Install Node.js >= v22 and npm >= v11. You will find it easier to use
the Node Version Manager nvm
To use the correct version of Node.js for this application, via nvm:
cd aqie-maps-prototype
nvm useThe GOV.UK Prototype Kit is a tool for building interactive prototypes that look like pages on GOV.UK, it provides components and styles from the GOV.UK Frontend. Both are provided by the Government Digital Service (GDS), this template provides both tools in a wrapper that runs on the Core Delivery Platform at Defra.
Note
The GOV.UK Prototype Kit is built with express.js. The Node.js
applications cdp-node-frontend-template
and cdp-node-backend-template at Defra are built with
Hapi.js
- For information on the
GOV.UK Prototype Kitsee https://prototype-kit.service.gov.uk/docs/ - For tutorials on how to use the
GOV.UK Prototype Kitsee https://prototype-kit.service.gov.uk/docs/tutorials-and-guides - For help with the underlying
GOV.UK Frontendsee:
Warning
The aqie-maps-prototype is not a production ready application, it is a tool for prototyping. It is not
designed to be used in production or to be resilient, secure or performant, nor should it be. It is designed to be
used for prototyping ideas and testing them with users. It's a great tool for prototyping GOV web applications.
The refreshed GOV.UK brand is available and turned on by default in the aqie-maps-prototype. To turn it
off simply go to app/config.json and set the "rebrand" property to false. This will turn off
the refreshed brand and use the legacy brand instead.
{
"plugins": {
"govuk-frontend": {
"rebrand": true
}
}
}Caution
Do not commit the .env file to GitHub, it is in the .gitignore file by default. Sensitive information such as a
password can be provided to a prototype via the Secrets page of your prototype in the CDP Portal Frontend
Basic authentication is on by default in CDP environments for prototypes. This means you will need to set a password for your prototype. You can do this via your prototypes secrets tab in the Portal Frontend. For information on how to do this, follow these steps:
- Read the Setting a password section on https://prototype-kit.service.gov.uk/docs/publishing
- Go to the CDP Portal Frontend
- Log in
- Navigate to your prototype on the services list page
- Navigate to your prototypes
Secretstab - Add a secret with a name
PASSWORDand avalueof your choosing - Re-deploy your prototype for the new secrets to be made available to it
The GOV.UK Prototype Kit has the ability to set up multiple passwords via secrets. For more information on how to do
this read the If you want to create additional passwords section on
https://prototype-kit.service.gov.uk/docs/publishing. To add a secret to an environment your prototype is running in
see Creating a secret
By default, the GOV.UK Prototype Kit requires a password has been set on your prototype when it has been deployed to
an environment. If you would like to turn off this requirement you can do so by setting the following environment
variable:
ENV USE_AUTH=falseThis can be set in cdp-app-config for instructions on how to do so
read Environment Variables on CDP.
All available Npm scripts can be seen in package.json To view them in your command line run:
npm runTo update dependencies use npm-check-updates:
The following script is a good start. Check out all the options on the npm-check-updates
ncu --interactive --format groupEnvironment variables and Secrets are used to configure your prototype. Where you set them can be seen in the table below.
| Type | Environment | Where to set them |
|---|---|---|
| Sensitive secrets and Non-sensitive environment variables | local | .env file |
| Sensitive secrets | CDP | CDP Portal Frontend services secrets page |
| Non-sensitive environment variables | CDP | CDP App Config repository by raising a pull request |
Caution
Do not store passwords in GitHub. Sensitive information such as a password can be provided to a prototype via the
secrets page in the CDP Portal Frontend. The .env file is for local development only.
To set environment variables and secrets locally copy the .env.template file to .env and add any
environment variables or secrets your local environment needs.
When your prototype is running on a CDP environment, E.g. dev or ext-test. You can set environment variables via a
GitHub pull request.
To add environment variables read - https://github.com/DEFRA/cdp-documentation/blob/main/how-to/config.md. This will guide you to add non-sensitive environment variables to the https://github.com/DEFRA/cdp-app-config repository via a pull request.
The following environment variables are available in the GOV.UK Prototype Kit. For more information see
their https://prototype-kit.service.gov.uk/docs/ or https://github.com/alphagov/govuk-prototype-kit.
| Name | Value | Description |
|---|---|---|
PASSWORD |
string |
Password for basic authentication |
PASSWORD_KEYS |
string |
Comma-separated list of keys for password authentication |
To add sensitive environment variables know as secrets to your prototype. Add them via your prototypes secrets page on the CDP Portal.
- Go to the CDP Portal Frontend
- Log in
- Navigate to your prototype on the services list page
- Navigate to your prototypes
Secretstab - Add a secret on your chosen environment with a
nameandvalueof your choosing - Re-deploy your prototype for the new secrets to be made available to it
This prototype consumes data from the aqie-back-end service. You will need a running instance of it to see real data locally — without it the app will still load but the homepage will show a Not Connected banner.
The easiest way to run aqie-back-end locally is via its own Docker Compose file. From the aqie-back-end
directory:
docker compose up --buildThis starts aqie-back-end on port 3001 and creates the shared cdp-tenant Docker network that this prototype
also joins (see Docker Compose).
Once it is running, verify connectivity:
curl http://localhost:3001/healthWhen running both services via Docker Compose, AQIE_BACK_END_URL is automatically set to
http://aqie-back-end:3001 using Docker's internal networking — no manual configuration needed.
| Endpoint | Description |
|---|---|
GET /health |
Health check — used by the homepage connectivity banner |
GET /forecasts |
Air quality forecasts stored in MongoDB (populated by cron 5–10am) |
GET /measurements |
Pollutant measurements stored in MongoDB |
GET /monitoringStations |
Cached monitoring station metadata from MongoDB (populated on startup, refreshed every 6 hours) |
When this prototype is deployed to a CDP environment the AQIE_BACK_END_URL environment variable must be
set to the internal URL of the aqie-back-end service running in that environment (e.g. http://aqie-back-end).
Add the variable via a pull request to the cdp-app-config repository. See Environment Variables on CDP for step-by-step guidance.
For the most part you will not need to be concerned with docker when running this prototype. Everything is set up and
your docker will automatically be built, published and pushed when you deploy a new version of your prototype via the
UI in the CDP Portal.
The recommended way to run this prototype locally alongside aqie-back-end. Both services join the shared
cdp-tenant Docker network, so they can reach each other by service name.
Important
Start aqie-back-end first (via docker compose up --build in its directory) so the cdp-tenant network exists
before this prototype starts.
Build and start:
docker compose up --buildStop:
docker compose downThe AQIE_BACK_END_URL is automatically set to http://aqie-back-end:3001 inside the container. Other variables
(e.g. PASSWORD) are loaded from your .env file — copy .env.template to .env if you
haven't already.
Build:
docker build --no-cache --tag aqie-maps-prototype .Run:
Update the password field to your password. On Linux,
--add-hostis required so the container can reachaqie-back-endrunning on your host machine.
docker run \
--add-host=host.docker.internal:host-gateway \
-e PASSWORD=beepBoopBeep \
-e PORT=3000 \
-e AQIE_BACK_END_URL=http://host.docker.internal:3001 \
-p 3000:3000 \
aqie-maps-prototypeTo debug issues in docker and to have a look at the built docker container in the same way as when it runs on CDP. You can run an interactive shell:
Build:
docker build --no-cache --tag aqie-maps-prototype .Run:
docker run -it --entrypoint /bin/ash aqie-maps-prototypeTHIS INFORMATION IS LICENSED UNDER THE CONDITIONS OF THE OPEN GOVERNMENT LICENCE found at:
http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3
The following attribution statement MUST be cited in your products and applications when using this information.
Contains public sector information licensed under the Open Government license v3
The Open Government Licence (OGL) was developed by the Controller of Her Majesty's Stationery Office (HMSO) to enable information providers in the public sector to license the use and re-use of their information under a common open licence.
It is designed to encourage use and re-use of information freely and flexibly, with only a few conditions.