This web app allows you to enter keywords for a SIC code search using the sic-code-api. A SIC Code is an abbreviation of "Standard industrial classification of economic activities".
It has one screen with a search form, with the following input fields:
- search text: add one or more keywords to be used in the search (the search is case insensitive).
- match phrase checkbox: if selected then results will only be returned if the exact phrase is present.
When this form is submitted then the search parameters are posted to the sic-code-api and the results are displayed with the search parameters.
This Node.js application is based on the Node Web Starter template in 2022 and uses:
- Express,
- TypeScript,
- GovUK Frontend.
Axiosto call thesic-code-api
The recommended local development testing method is to use Docker CHS Development and chs-dev.
- Run
chs-dev modules enable sic-code - Run
chs-dev development enable sic-code-web(this will allow you to make changes in real time). - Run docker using
chs-dev upin thedocker-chs-developmentdirectory. - Open your browser and go to page http://chs.local/sic-code-search
This 'Docker CHS Development' project has:
- Environment variables used to configure this service in docker are located in the file
services/modules/sic-code/sic-code-web.docker-compose.yaml. - The database file to add more data for this environment is in 'services/modules/sic-code/assets/database.mongo.js'
- Enable development mode (see last section). Note that the
inspect optionis added in thepackage.jsonfile just before the call totsnodeto avoid "address already in use" message - In Docker CHS Development project file
services/modules/sic-code/sic-code-web.docker-compose.yamladd an extra line to the ports section to allow the debugger port to be viewed outside of docker. Do not push this change to the master branch of Docker CHS Development
ports:
- 3000:3000
- 9229:9229- Use Confluence guide on debugging within Docker CHS Development to configure your IDE to attach to the debugger port after the existing application listening port (3000).
In the node log you will see a message something like
[nodemon] starting `NODE_OPTIONS=--inspect=0.0.0.0:9229 ts-node ./src/server.ts`
Debugger listening on ws://0.0.0.0:9229/cff146e9-f30b-4bfb-af0e-168bb18d7b81
For help, see: https://nodejs.org/en/docs/inspector
{"created":"2023-10-20T09:03:48.088+00:00","event":"debug","namespace":"sic-code-web","data":{"message":"Starting app in mode [development] using CDN [http://cdn.chs.local] and sic-code-api at [http://api.chs.local:4001]"}}
server listening on 0.0.0.0:3000- To compile the project use
make build - To test the project use
make test - or
make clean build test
Still start the docker environment above so that you can access the sic-code-api and CDN
Set environmental variables as in services/modules/sic-code/sic-code-web.docker-compose.yaml
npm run dev
Go to browser at http://localhost:3000/sic-code-search
The following is a list of environment variables for the service to run (but these are already set up when using docker-chs-development)
| Name | Description | Example Value |
|---|---|---|
| INTERNAL_API_URL | Base URL to sic-code-api |
http://internalapi |
| CHS_INTERNAL_API_KEY | API Key for calling the sic-code-api |
|
| SIC_CODE_API_TIMEOUT_MILLISECONDS | API call timeout in milliseconds | 10000 (default) |
| SIC_CODE_WEB_PORT | Application port number | 3000 (default) |
| CDN_HOST | Path to CH Styling for this application | View the page source of the DevHub page - example https://d3q1r7ldqt8xxd.cloudfront.net/ |
Jest is used in testing
npm run test
npm run test:coverage
TSLint is used to perform static analysis on code style.
npm run lint