Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
node-ocpi
Advanced tools
Readme
node-ocpi
is an advanced Node.js library designed for implementing the Open Charge Point Interface (OCPI) protocol. Offering structured models and comprehensive validation for various OCPI entities, it serves as an essential toolkit for developers in the electric vehicle (EV) charging station domain.
Location
, EVSE
, Connector
, CDR
, Command
, Feedback
, Meter
, Reservation
, Tariff
, User
, Transaction
, Credentials
, ChargingProfilePeriod
, ChargingProfile
, ActiveChargingProfile
, ChargingProfileResponse
, ActiveChargingProfileResult
, ChargingProfileResult
, ClearProfileResult
, SetChargingProfile
, CommandResult
, CommandResponse
, DisplayText
, EnergyContract
, LocationReferences
, Token
, AuthorizationInfo
, and OCPIResponse
.Install node-ocpi
using npm:
npm install https://github.com/hyndex/node-ocpi
Import the required models from node-ocpi
:
const {
Location, EVSE, Connector, CDR, Command, Feedback, Meter, Reservation, Tariff, User, Transaction, Credentials,
ChargingProfilePeriod, ChargingProfile, ActiveChargingProfile, ChargingProfileResponse, ActiveChargingProfileResult, ChargingProfileResult, ClearProfileResult, SetChargingProfile,
CommandResult, CommandResponse,
DisplayText, EnergyContract, LocationReferences, Token, AuthorizationInfo, OCPIResponse
} = require('node-ocpi');
const location = new Location({ /* Location data */ });
location.validate();
const commandResult = new CommandResult({
result: 'ACCEPTED',
message: 'Command successfully executed'
});
commandResult.validate();
const commandResponse = new CommandResponse({
result: 'REJECTED',
timeout: 30,
message: 'Command could not be executed'
});
commandResponse.validate();
const ocpiResponse = new OCPIResponse({
statusCode: 2000,
statusMessage: 'Success',
timestamp: new Date().toISOString(),
data: { /* Your data object or array */ }
});
OCPIResponse.schema(YOUR_MODEL_SCHEMA).validate(ocpiResponse);
... (Continue with other models similarly)
Integrate node-ocpi
in Express.js applications for efficient handling of OCPI data:
const express = require('express');
const { Location } = require('node-ocpi');
const app = express();
app.use(express.json());
app.post('/locations', (req, res) => {
try {
const location = new Location(req.body);
location.validate();
res.status(201).send(location);
} catch (error) {
res.status(400).send(error.message);
}
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});
Contributions are welcome:
node-ocpi
is released under the MIT License. See LICENSE for details.
FAQs
An OCPI library for Node.js
The npm package node-ocpi receives a total of 28 weekly downloads. As such, node-ocpi popularity was classified as not popular.
We found that node-ocpi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.