Skip to content

Programs

Membrane is similar to an operating system; you deploy programs to the Membrane engine, and it takes care of persistence, communication, logging, resources, etc.

A Membrane program is TypeScript or JavaScript code that runs in Membrane’s serverless cloud runtime. Unlike traditional serverless runtimes, it is stateful and includes multiple handlers instead of a single function.

A Membrane program consists of:

  • Code: TypeScript/JavaScript functions for fields, actions and events
  • Schema: nodes exposed in the graph—the program’s own API
  • Connections: other programs—nodes—used by the program
  • Implicit Handlers: optional functions, e.g. to receive HTTP requests

In Membrane, you build custom functionality (bots, workflows, etc.) by writing programs. Programs can reference each other’s nodes to create powerful abstractions.

Code organization

A Membrane program contains at least three files:

  • Directoryyour-program/
    • index.ts
    • memconfig.json
    • memconfig.lock
  1. index.ts|js: contains core logic and exports resolver functions
  2. memconfig.json: describes your schema with all fields, actions, events, and connections. It’s automatically generated, so you should never have to edit this file by hand
  3. memconfig.lock: tracks versions of nodes in your graph. It’s also automatically generated, and you should never have to edit it manually

Your program’s directory may also include a README.md, package.json with npm dependencies, .git, and whatever other helpers and structure you’d like.

Stopping and deleting programs

To stop a running program, right click the program in the Membrane Navigator and select Kill from the dropdown menu. A program must be stopped in order to delete it.

To delete a program, right click the program’s folder in your file explorer and select Delete from the dropdown menu. Or, open the command palette (Cmd+Shift+P on Mac) and type Membrane: Delete Program. A message will appear in the bottom bar of your editor upon deletion.