Node.js
prototype template, using the GOV.UK Prototype Kit and
the GOV.UK Frontend.
Basically the
GOV.UK Prototype Kit
andGOV.UK Frontend
wrapped 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
- 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 nrf-prototypes
nvm use
The 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 Kit
see https://prototype-kit.service.gov.uk/docs/ - For tutorials on how to use the
GOV.UK Prototype Kit
see https://prototype-kit.service.gov.uk/docs/tutorials-and-guides - For help with the underlying
GOV.UK Frontend
see:
Warning
The nrf-prototypes
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 nrf-prototypes
. 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
Secrets
tab - Add a secret with a name
PASSWORD
and avalue
of 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=false
This 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 run
To 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 group
Environment 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
Secrets
tab - Add a secret on your chosen environment with a
name
andvalue
of your choosing - Re-deploy your prototype for the new secrets to be made available to it
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.
Build:
docker build --target development --no-cache --tag nrf-prototypes:development .
Run:
docker run -e PORT=3000 -p 3000:3000 nrf-prototypes:development
Build:
docker build --no-cache --tag nrf-prototypes .
Run:
Update the password field to your password
docker run -e PASSWORD=beepBoopBeep -e PORT=3000 -p 3000:3000 nrf-prototypes
To 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 nrf-prototypes .
Run:
docker run -it --entrypoint /bin/ash nrf-prototypes
THIS 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.