OCPP in Node.js: Build a CSMS with ocpp-ws-io
Build an OCPP server or client in Node.js and TypeScript with ocpp-ws-io — an OCPP RPC WebSocket library for 1.6J, 2.0.1 and 2.1 — and test it with the simulator.
OCPP in Node.js
OCPP-J is JSON over WebSocket, which makes Node.js a natural fit for a CSMS: one process can hold thousands of charger connections and handle their messages asynchronously. What you don't want to write by hand is the protocol plumbing — message framing, matching responses to requests, timeouts and the OCPP error codes.
ocpp-ws-io is an OCPP RPC WebSocket library for Node.js and TypeScript that does exactly that, for OCPP 1.6J, 2.0.1 and 2.1. It is also what powers this simulator, so the same library sits on both ends of your tests.
What “OCPP RPC” means
OCPP-J sends remote procedure calls as JSON arrays. A CALL is [2, id, action, payload]; the receiver replies with a CALLRESULT [3, id, payload] or a CALLERROR [4, id, code, description, details]. An OCPP RPC library handles that framing, so your code works with typed requests and responses.
What ocpp-ws-io gives you
OCPP 1.6J, 2.0.1 and 2.1
Full OCPP-J RPC framing with version-aware handlers.
Type-safe TypeScript
Generated types for every OCPP action and payload.
Schema validation
Optional strict JSON schema validation of messages.
All security profiles
Plain WebSocket, Basic Auth, TLS and mutual TLS.
Scales out
Redis pub/sub clustering for multi-node CSMS deployments.
Client, server and browser
Server and client for Node.js, plus a browser client.
Build a minimal CSMS
Install the package:
npm install ocpp-ws-ioThen start a server that accepts OCPP 1.6J and 2.0.1 chargers and answers their BootNotification:
import { OCPPServer } from "ocpp-ws-io";
const server = new OCPPServer({
protocols: ["ocpp1.6", "ocpp2.0.1"],
logging: { prettify: true, exchangeLog: true, level: "info" },
});
server.on("client", (client) => {
console.log(`${client.identity} connected`);
client.handle("ocpp1.6", "BootNotification", ({ params }) => {
console.log("Boot from:", params.chargePointVendor);
return {
status: "Accepted",
currentTime: new Date().toISOString(),
interval: 300,
};
});
});
await server.listen(9000);Test it with the simulator
- Run the server above; it listens on
ws://localhost:9000. - Open the simulator, keep the endpoint
ws://localhost:9000and select Connect. - Your server logs the connection and the BootNotification. Add more handlers — Authorize, StartTransaction, MeterValues — and drive them from the simulator.
Or write a charge point in Node.js
The same library also works on the charger side, for scripted tests and headless simulators:
import { OCPPClient } from "ocpp-ws-io";
const client = new OCPPClient({
endpoint: "ws://localhost:9000",
identity: "CP001",
protocols: ["ocpp1.6"],
});
client.handle("ocpp1.6", "Reset", async ({ params }) => {
console.log("Reset requested:", params.type);
return { status: "Accepted" };
});
await client.connect();
const response = await client.call("ocpp1.6", "BootNotification", {
chargePointVendor: "VendorX",
chargePointModel: "ModelY",
});
console.log("Status:", response.status);Full API reference and guides: ocpp-ws-io documentation · npm · GitHub.
Point the simulator at your Node.js CSMS
Connect a virtual charge point to ws://localhost:9000 and watch every OCPP message.
Frequently asked questions
What is the best way to use OCPP in Node.js?
Use an OCPP-J RPC library that handles the WebSocket connection, message framing, request/response matching and error codes for you. ocpp-ws-io is one such library: it supports OCPP 1.6J, 2.0.1 and 2.1 with typed messages in TypeScript.
What does OCPP RPC mean?
OCPP-J carries remote procedure calls over WebSocket as JSON arrays: a CALL [2, id, action, payload], answered by a CALLRESULT [3, id, payload] or a CALLERROR [4, id, code, description, details]. An OCPP RPC library implements that framing for you.
Is ocpp-ws-io an alternative to ocpp-rpc?
Both are open-source Node.js libraries for the OCPP-J RPC framing. ocpp-ws-io adds typed messages for OCPP 1.6J, 2.0.1 and 2.1, optional JSON schema validation, all security profiles, Redis clustering and a browser client. Compare both projects' documentation to choose what fits your stack.
How do I test my Node.js CSMS?
Start your server, open the OCPP WS Simulator, set the endpoint to your server's WebSocket URL (for example ws://localhost:9000) and connect. The simulator acts as a real charge point.