Node.js
REVIEWHere’s a list of our preferred technology choices when implementing in Node.js. We’re not prescriptive in these choices, but have a good reason to deviate from the norm. If you there’s a better option, raise it at the Developer Community.
Node.js versions
Refer to the Release adoption schedule
Node projects must:
- use NVM to manage Node versions in development
- use an
.nvmrc
file, checked in to source control, to identify the Node version in use
IDE
Choose whatever you’re comfortable with, so as long as you can perform your
job. Our developers tend to use VS Code.
Build
- Code coverage provided by Jest
- Static analysis with SonarQube
- Sass for CSS preprocessing and building CSS assets
- Gulp is used for building clientside JavaScript assets
- TypeScript can be used as a typesafe superset of JavaScript to provide more confidence
- Prettier for opinionated code formatting
Application
Our standard JavaScript based application stack is built on Node.js.
- Environment variables retrieved using dotenv
- User interfaces using the NHS Frontend toolkit and Nunjucks for templating
- Web services with express
- Session handling with express-session and connect-redis using Redis as a session store
- Redis client if using Redis as a database
- Security with Helmet and csurf to prevent CSRF
- Dates and times are manipulated using Luxon or date-fns and not moment.js
- Logging provided by winston, express-winston and winston-daily-rotate-file
- Node Fetch to perform HTTP requests
- cookie-parser for working with cookies
- I18n for internationalisation
Testing
- Jest is our core testing framework
- SuperTest is used to provide high level HTTP testing of web services
- redis-mock for mocking of Redis in tests
- ESLint to ensure we’re using JavaScript correctly
Improve the playbook
If you spot anything factually incorrect with this page or have ideas for improvement, please share your suggestions.
Before you start, you will need a GitHub account. Github is an open forum where we collect feedback.
Published:
Last reviewed:
Next review due: