Skip to content

cerbos/getting-started-node

Getting Started - Node.js

An example application of integrating Cerbos with an Express server.

Dependencies

Getting Started

  1. Start up the Cerbos PDP instance docker container. This will be called by the Express app to check authorization.
cd cerbos
./start.sh
  1. Install node dependencies
npm install
  1. Start the Express server
npm run start

How it works

This example uses @cerbos/grpc to communicate with the Cerbos PDP over gRPC.

The Express server exposes three endpoints for managing articles:

  • GET /article/:id - Read an article
  • PATCH /article/:id - Update an article
  • DELETE /article/:id - Delete an article

Each endpoint calls cerbos.checkResource() to determine if the current user is authorized to perform the requested action based on the policies defined in the cerbos/policies directory.

The Cerbos policy (cerbos/policies/article.yaml) defines the following rules:

  • Admin and User roles can read and create articles
  • Admin role can update and delete any article
  • User role can only update and delete articles they own

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •