A Node.js backend API that allows users to search UK companies using Companies House data, apply filters, and export results.
- Search companies by keyword and various filters
- Filter by company status, type, SIC codes, incorporation date, location
- Export search results to CSV or JSON
- Save and manage filter presets
- Redis caching for improved performance
- Rate limiting and error handling
- Node.js 18+
- PostgreSQL
- Redis
- Companies House API key
- Clone the repository
- Install dependencies:
npm install- Set up PostgreSQL database:
psql -U your_username -d postgres
CREATE DATABASE companies_house_app;
\q
psql -U your_username -d companies_house_app < database/init.sql- Copy
.env.exampleto.envand configure:
cp .env.example .env- Update
.envwith your credentials:
CH_API_KEY: Your Companies House API keyDATABASE_URL: PostgreSQL connection stringREDIS_URL: Redis connection string
- Run the development server:
npm run devPOST /api/search
Content-Type: application/json
{
"filters": {
"keyword": "fintech",
"company_status": ["active"],
"company_type": ["ltd"],
"sic": ["64205"],
"incorporated_from": "2018-01-01",
"incorporated_to": "2025-09-03",
"postcode_prefix": "EC2",
"locality": "London"
},
"page": 1,
"page_size": 50
}
GET /api/export?token=<result_token>&format=csv
GET /api/export?token=<result_token>&format=json
GET /api/presets
POST /api/presets
DELETE /api/presets/:id
GET /health
src/
├── api/
│ ├── search/
│ ├── export/
│ └── presets/
├── config/
│ ├── database.ts
│ └── redis.ts
├── middleware/
│ └── errorHandler.ts
├── services/
│ └── companiesHouseApi.ts
├── types/
│ └── index.ts
└── index.ts
npm run dev- Start development server with hot reloadnpm run build- Build TypeScript to JavaScriptnpm start- Start production server
The API respects Companies House rate limits and implements:
- Request queuing and throttling
- Automatic retry with exponential backoff for 429 errors
- Redis caching to minimize API calls
All errors are handled consistently with appropriate HTTP status codes and error messages.
- Companies House API key is stored server-side only
- All external API calls are made from the server
- Input validation on all endpoints
- SQL injection protection via parameterized queries