Skip to main content

System Requirements

Before installing the EPR LAPS Backend API, ensure your system meets these requirements:

Required

  • Node.js >= v22.16.0
  • npm >= v11.0.0
  • MongoDB >= 5.0 (for local development)
  • nvm (Node Version Manager) for managing Node.js versions
  • Docker and Docker Compose for containerized development
  • Git for version control
The API requires Node.js v22 or higher. Using older versions will cause compatibility issues.

Installation Methods

Local Installation

1

Install Node.js

Install Node.js using nvm (recommended):
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

# Install Node.js v22
nvm install 22
nvm use 22

# Verify installation
node --version  # Should be >= v22.16.0
npm --version   # Should be >= v11.0.0
2

Clone Repository

Clone the EPR LAPS Backend repository:
git clone <repository-url>
cd epr-laps-backend
3

Use Correct Node Version

The project includes an .nvmrc file. Use it to automatically switch to the correct Node version:
nvm use
If you see “version not installed”, run nvm install first.
4

Install Dependencies

Install all project dependencies:
npm install
This will install:
  • Production dependencies from package.json
  • Development tools (ESLint, Prettier, Vitest)
  • Husky git hooks for code quality
The installation automatically runs npm run setup:husky to configure git hooks.
5

Install MongoDB

Install MongoDB for local development:
# Using Homebrew
brew tap mongodb/brew
brew install mongodb-community
brew services start mongodb-community
6

Verify Installation

Verify all components are installed:
# Check Node.js
node --version

# Check npm
npm --version

# Check MongoDB connection
mongosh --eval "db.adminCommand('ping')"

# View available npm scripts
npm run

Configuration

Environment Variables

The API uses environment variables for configuration. Create a .env file or export these variables:
# Node Environment
NODE_ENV=development

# Server Configuration
HOST=0.0.0.0
PORT=3001

# MongoDB Configuration
MONGO_URI=mongodb://127.0.0.1:27017/
MONGO_DATABASE=epr-laps-backend

# Authentication
DEFRA_ID_DISCOVERY_URL=http://localhost:3200/cdp-defra-id-stub/.well-known/openid-configuration
DEFRA_ID_ISSUER=http://localhost:3200/cdp-defra-id-stub

# FSS API Integration
FSS_API_URL=http://localhost:3003/api
FSS_API_KEY=some-api-key
FSS_API_ENCRYPTION_KEY=your-base64-encryption-key

Configuration Schema

The API uses Convict for configuration management with validation:
// From src/config.js
import convict from 'convict'
import convictFormatWithValidator from 'convict-format-with-validator'

const config = convict({
  serviceName: {
    doc: 'Api Service Name',
    format: String,
    default: 'epr-laps-backend'
  },
  port: {
    doc: 'The port to bind',
    format: 'port',
    default: 3001,
    env: 'PORT'
  },
  mongo: {
    mongoUrl: {
      doc: 'URI for mongodb',
      format: String,
      default: 'mongodb://127.0.0.1:27017/',
      env: 'MONGO_URI'
    },
    databaseName: {
      doc: 'database for mongodb',
      format: String,
      default: 'epr-laps-backend',
      env: 'MONGO_DATABASE'
    }
  }
})

config.validate({ allowed: 'strict' })
Configuration validation runs on startup. Invalid configuration will prevent the server from starting.

Package Dependencies

The API uses the following core dependencies:

Production Dependencies

{
  "@hapi/hapi": "21.4.6",
  "@hapi/boom": "10.0.1",
  "hapi-auth-jwt2": "11.0.0",
  "mongodb": "7.1.0",
  "mongo-locks": "3.1.2",
  "joi": "18.0.2",
  "convict": "6.2.4",
  "pino": "10.3.1",
  "hapi-pino": "13.0.0",
  "undici": "7.22.0",
  "@defra/hapi-tracing": "1.30.0",
  "@defra/cdp-auditing": "0.6.0"
}

Development Dependencies

{
  "vitest": "4.0.18",
  "@vitest/coverage-v8": "4.0.18",
  "eslint": "9.29.0",
  "neostandard": "0.13.0",
  "prettier": "3.8.1",
  "nodemon": "3.1.14",
  "husky": "9.1.7"
}

Updating Dependencies

Keep dependencies up to date using npm-check-updates:
1

Install npm-check-updates

npm install -g npm-check-updates
2

Check for Updates

ncu --interactive --format group
3

Update Dependencies

# Update package.json
ncu -u

# Install updated packages
npm install
4

Run Tests

npm test

Running the Application

After installation, you can run the API in different modes:
# Start with hot-reload and debugging
npm run dev

# Server runs on http://0.0.0.0:3001
# Debug inspector available on port 9229

Code Quality Tools

Linting

The project uses ESLint with neostandard configuration:
# Check for linting errors
npm run lint

# Auto-fix linting errors
npm run lint:fix

Formatting

Prettier is configured for consistent code formatting:
# Check formatting
npm run format:check

# Auto-format code
npm run format

Git Hooks

Husky automatically runs quality checks before commits:
# Pre-commit hook runs:
# 1. npm run format:check
# 2. npm run lint
On Windows, if you encounter Prettier line break issues, run:
git config --global core.autocrlf false

Testing

The API uses Vitest for testing with coverage reporting:
# Run all tests with coverage
npm test

# Coverage reports are generated in ./coverage/

Troubleshooting

On Linux/macOS, you may need to fix npm permissions:
# Change npm default directory
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
Verify MongoDB is running and accessible:
# Test connection
mongosh mongodb://127.0.0.1:27017/

# Check MongoDB status
sudo systemctl status mongod

# Check Docker MongoDB
docker ps | grep mongo
Ensure you’re using Node.js v22:
# Check current version
node --version

# Switch to correct version
nvm use 22

# Or install if needed
nvm install 22
Reinstall git hooks:
npm run setup:husky

# Or manually
npx husky install
Clear Docker cache and rebuild:
# Remove old images
docker rmi epr-laps-backend:development epr-laps-backend

# Rebuild without cache
docker build --no-cache --tag epr-laps-backend .

Next Steps

Quick Start Guide

Get the API running and test your installation

API Reference

Explore available API endpoints and usage

Configuration

Deep dive into configuration options

Development Guide

Learn about development workflows and best practices

Build docs developers (and LLMs) love