{"id":20039196,"url":"https://github.com/defra/hapi-web-boilerplate","last_synced_at":"2025-10-19T04:05:02.217Z","repository":{"id":33179403,"uuid":"148623358","full_name":"DEFRA/hapi-web-boilerplate","owner":"DEFRA","description":"hapijs boilerplate govuk web project","archived":false,"fork":false,"pushed_at":"2025-03-24T13:54:10.000Z","size":453,"stargazers_count":9,"open_issues_count":3,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-08T19:08:22.998Z","etag":null,"topics":["government","govuk","hapijs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DEFRA.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-13T10:42:16.000Z","updated_at":"2025-03-24T13:39:55.000Z","dependencies_parsed_at":"2023-01-14T23:48:00.370Z","dependency_job_id":null,"html_url":"https://github.com/DEFRA/hapi-web-boilerplate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEFRA%2Fhapi-web-boilerplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEFRA%2Fhapi-web-boilerplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEFRA%2Fhapi-web-boilerplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEFRA%2Fhapi-web-boilerplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DEFRA","download_url":"https://codeload.github.com/DEFRA/hapi-web-boilerplate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252458594,"owners_count":21751068,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["government","govuk","hapijs"],"created_at":"2024-11-13T10:36:19.947Z","updated_at":"2025-10-19T04:05:02.169Z","avatar_url":"https://github.com/DEFRA.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# (Enter service name)\n(Description of the service)\n\n# Environment variables\n(Be sure to describe any environment variables here by maintaining a list like this)\n\n| name     | description      | required | default |            valid            | notes |\n|----------|------------------|:--------:|---------|:---------------------------:|-------|\n| NODE_ENV | Node environment |    no    |         | development,test,production |       |\n| PORT     | Port number      |    no    | 3000    |                             |       |\n\n# Prerequisites\n\nNode v8+\n\n\n# (Checklist)\nOnce you clone this repository you'll need to make a few changes before you're ready to start:\n\n- [ ] Add service name and description to the README above\n- [ ] Check over the content of the 404 and 500 error pages and tailor to suit\n- [ ] Update the `package.json` with the name, description and any git urls and authors etc.\n- [ ] Update the [views context data](/server/plugins/views.js#L39) to include the correct service and default page title\n- [ ] Remove the .git folder in the root directory. This will cut the cord to this boilerplate repo.\n- [ ] Update the build status badges to your new project\n\n# Running the application\n\nFirst build the application using:\n\n`$ npm run build`\n\nCurrently this will just build the `govuk-frontend` sass but may be extended to include other build tasks as needed (e.g. client-side js using browserify or webpack etc.)\n\nNow the application is ready to run:\n\n`$ node index.js`\n\n\n(You can delete the remainder of this readme once you're up and running)\n\n## What is this?\n\nA simple hapi-based enterprise ready govuk web application boilerplate.\nClick here for a similar [api boilerplate hapi project](https://github.com/DEFRA/hapi-api-boilerplate).\n\nBased on:\n\n- [hapijs](https://github.com/hapijs/hapi) - The framework \u0026 core plugins like `joi`, `vision` etc.\n- [neostandard](https://github.com/neostandard/neostandard) - Linting\n- [govuk-frontend](https://github.com/alphagov/govuk-frontend) - Styles \u0026 macros\n- [nunjucks](http://mozilla.github.io/nunjucks/) - Default template engine\n- [npm-scripts](https://docs.npmjs.com/misc/scripts) - Build tool\n- [pm2](https://github.com/Unitech/pm2) - Process manager\n\n\n## Getting started\n\nClone this repo and run through the checklist above.\n\nCheck the server is running by pointing your browser to `http://localhost:3000`\n\n## Project structure\n\nHere's the default structure for your project files.\n\n* **bin** (build tasks)\n* **client** (client js/sass code)\n* **server**\n  * **plugins**\n  * **public**  (This folder is publicly served)\n    * **static** (Put all static assets in here)\n    * **build** (This contains the build output files (js/css etc.) and is not checked-in)\n  * **routes**\n  * **views**\n  * config.js\n  * index.js (Exports a function that creates a server)\n* **test**\n* README.md\n* index.js (startup server)\n\n## Config\n\nThe configuration file for the server is found at `server/config.js`.\nThis is where to put any config and all config should be read from the environment.\nThe final config object should be validated using joi and the application should not start otherwise.\n\nA table of environment variables should be maintained in this README.\n\n## Plugins\n\nhapi has a powerful plugin system and all server code should be loaded in a plugin.\n\nPlugins live in the `server/plugins` directory.\n\n## Logging\n\nThe [good](https://github.com/hapijs/good) and [good-console](https://github.com/hapijs/good-console) plugins are included and configured in `server/plugins/logging`\n\nThe logging plugin is only registered in when `NODE_ENV=development`.\n\nError logging for production should use errbit.\n\n## Views\n\nThe [vison](https://github.com/hapijs/vision) plugin is used for template rendering support.\n\nThe template engine used in nunjucks inline with the GDS Design System with support for view caching, layouts, partials and helpers.\n\n## Static files\n\nThe [Inert](https://github.com/hapijs/inert) plugin is used for static file and directory handling in hapi.js.\nPut all static assets in `server/public/static`.\n\nAny build output should write to `server/public/build`. This path is in the `.gitignore` and is therefore not checked into source control.\n\n## Routes\n\nIncoming requests are handled by the server via routes.\nEach route describes an HTTP endpoint with a path, method, and other properties.\n\nRoutes are found in the `server/routes` directory and loaded using the `server/plugins/router.js` plugin.\n\nHapi supports registering routes individually or in a batch.\nEach route file can therefore export a single route object or an array of route objects.\n\nA single route looks like this:\n\n```js\n{\n  method: 'GET',\n  path: '/hello-world',\n  options: {\n    handler: (request, h) =\u003e {\n      return 'hello world'\n    }\n  }\n}\n```\n\nThere are lots of [route options](http://hapijs.com/api#route-options), here's the documentation on [hapi routes](http://hapijs.com/tutorials/routing)\n\n## Tasks\n\nBuild tasks are created using simple shell scripts or node.js programs.\nThe default ones are found in the `bin` directory.\n\nThe task runner is simply `npm` using `npm-scripts`.\n\nWe chose to use this for simplicity but there's nothing to stop you adding `gulp`, `grunt` or another task runner if you prefer.\n\nThe predefined tasks are:\n\n- `npm run build` (Runs all build sub-tasks)\n- `npm run build:css` (Builds the client-side sass)\n- `npm run lint` (Runs the lint task using standard.js)\n- `npm run unit-test` (Runs the `lab` tests in the `/test` folder)\n- `npm test` (Runs the `lint` task then the `unit-tests`)\n\n### Resources\n\nFor more information around using `npm-scripts` as a build tool:\n\n- http://substack.net/task_automation_with_npm_run\n- http://ponyfoo.com/articles/choose-grunt-gulp-or-npm\n- http://blog.keithcirkel.co.uk/why-we-should-stop-using-grunt/\n- http://blog.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/\n\n## Testing\n\n[jest](https://https://jestjs.io/) is used for unit testing.\n\nSee the `/__test__` folder for more information.\n\n## Linting\n\n[neostandard](https://github.com/neostandard/neostandard) is used to lint both the server-side and client-side javascript code.\n\nIt's defined as a build task and can be run using `npm run lint`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefra%2Fhapi-web-boilerplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdefra%2Fhapi-web-boilerplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefra%2Fhapi-web-boilerplate/lists"}