OCPP Node Libraryfastify-ocppnpm1.6 · 2.0.1 · 2.1GPL-3.0

OCPP Node Library

The npm package that turns a Node server into an OCPP-J CSMS endpoint — negotiation, framing, schema validation, and a clean handler API.

Install `fastify-ocpp`, register once, then own BootNotification, Authorize, transactions, and outbound Reset / remote start in your code — not in a fork of the wire protocol.

From npm

fastify-ocpp

install

npm i fastify-ocpp

register

register(fastifyOcpp, { versions, path })

api

ocpp.onAction · ocpp.call · registry

Package

fastify-ocpp @1.0.0

Runtime

Node.js 18+

Types

TypeScript included

Package surface

What you get when you install

1

versions + shared path

Configure `versions: ['2.1','2.0.1','1.6']` and `path: '/ocpp'`. Stations hit one route; Sec-WebSocket-Protocol picks the match.

2

onAction / onAny

Register handlers per action (optionally per version). Return a plain object — the package wraps CALLRESULT and validates it.

3

call + getConnection

Outbound CSMS→station CALLs with timeout. Inspect `conn.version` before choosing RemoteStart vs RequestStartTransaction.

4

OCA schemas (Ajv)

`validateIncoming` / `validateOutgoing` default on. Official Open Charge Alliance JSON schemas ship inside the package.

5

registry.list()

Live map of chargePointId → connection. Filter by negotiated version and gate operator commands on real presence.

6

Ops knobs built in

`callTimeoutMs`, `rejectDuplicateConnections`, `onConnect` / `onDisconnect` — production defaults without reinventing the session layer.

How it works

Install, register, wire handlers

1

Install the package

`npm i fastify-ocpp` (Node 18+). The package ships `dist/`, TypeScript types, and the OCA `schemas/` tree.

2

Register once

Pass `versions` (allow-list + preference) and `path`. You get `app.ocpp` — handlers, outbound call, and the registry.

3

Own the domain

Implement BootNotification, Heartbeat, Authorize, transactions. Use `ocpp.call` from your operator API for Reset and remote start.

Try it

From registry to first BootNotification

  1. 1Run `npm i fastify-ocpp` in a Node 18+ project.
  2. 2Register with `versions: ['2.1','2.0.1','1.6']` and `path: '/ocpp'`.
  3. 3Add `onAction('BootNotification')` and `onAction('Heartbeat')`, then point a simulator at `/ocpp/CP_001`.
  4. 4Read the protocol tutorial when you are ready for Authorize and full sessions.

Package facts

What ships on npm

Name

fastify-ocpp

Protocols

OCPP-J 1.6, 2.0.1, 2.1

Surface

onAction, call, registry, schemas

License

GPL-3.0-only

FAQ

Common questions

What exactly is fastify-ocpp?+
An npm library that adds an OCPP-J CSMS WebSocket endpoint to a Node app: subprotocol negotiation, CALL framing, OCA schema validation, handlers, and outbound call().
Does it include billing or roaming?+
No. Those live in your handlers and services. The package stops at a correct, validated OCPP conversation.
Which OCPP versions are supported?+
OCPP-J 1.6, 2.0.1, and 2.1 on one shared path. SOAP (OCPP-S) is not supported.
Where should my business logic live?+
In onAction handlers and application services that call ocpp.call. Do not fork the library to change tariffs or auth rules.

npm i fastify-ocpp — then wire your first handler.

Grab the package on npm, clone the repo, or read the CSMS tutorial when you want the full protocol walkthrough.