Skip to content

nhsuk/nhsuk-prototype-kit-package

Repository files navigation

NHS prototype kit

This repo contains the code for the NHS Prototype kit that will be distributed as an npm package.

The code contains:

  • an Express middleware app
  • some useful default settings for Express
  • some Nunjucks filters
  • Nunjucks views, including a template

Installing the kit

Using the template repository

The simplest way to get started is to use the NHS Prototype kit template repository.

From there, select 'Use this as a template' and follow the instructions.

Manual installation

You can also add the kit to an existing Express app by running:

npm install nhsuk-prototype-kit

Then, within your app.js file, add this line to the top:

import NHSPrototypeKit from 'nhsuk-prototype-kit'

Or, if using CommonJS:

const NHSPrototypeKit = require('nhsuk-prototype-kit')

Initialise the prototype with a reference to your custom routes like this:

import routes from './app/routes.js'

const prototype = await NHSPrototypeKit.init({
  serviceName: 'Your service name',
  buildOptions: {
    entryPoints: ['app/stylesheets/*.scss']
  },
  routes
})

You can then start the prototype using this:

prototype.start()

If you want to set session data defaults, or locals, pass them to the init function:

import sessionDataDefaults from './app/data/session-data-defaults.js'
import locals from './app/locals.js'
import routes from './app/routes.js'

const prototype = await NHSPrototypeKit.init({
  serviceName: 'Your service name',
  buildOptions: {
    entryPoints: ['app/stylesheets/*.scss']
  },
  routes,
  locals,
  sessionDataDefaults
})

Using the Nunjucks filters only

If you only want to use the Nunjucks filters, you can import them separately:

import { nunjucksFilters } from 'nhsuk-prototype-kit'

nunjucksFilters.addAll(nunjucksEnv)

Or import individual filters:

import { nunjucksFilters } from 'nhsuk-prototype-kit'

nunjucksEnv.addFilter('formatNhsNumber', nunjucksFilters.formatNhsNumber)
nunjucksEnv.addFilter('startsWith', nunjucksFilters.startsWith)

Using the Express middleware only

If you only want to use the Express middleware, you can import it separately:

import { middleware } from 'nhsuk-prototype-kit'

middleware.configure({
  app: app,
  serviceName: serviceName,
  locals: locals,
  routes: routes,
  sessionDataDefaults: sessionDataDefaults
})

Or you can choose to only use individual middleware functions:

import { middleware } from 'nhsuk-prototype-kit'

app.use(middleware.autoRoutes)

Using the utilities

You can also import the utility functions separately:

import { utils } from 'nhsuk-prototype-kit'

const port = await utils.findAvailablePort(3000)

About

Rapidly create HTML prototypes of NHS services

Resources

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •