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.

Example: GitHub notifications in Discord

As a starting user, you’ll first install drivers to talk to APIs for apps you already use, then write programs using the nodes exposed by those drivers to build something useful to you or your team. You can also always use fetch and/or build your own drivers if you want.

For example, you could write a program that listens to a GitHub repo and sends you messages in Discord when there are new commits (this program already exists, if you’re interested).

Or maybe you’d like the notification in Slack, or via email, or even via text. You can edit the program however you’d like—a Membrane program exposes the full power of whatever you can code, but lowers friction with built-in persistence and utilities out of the box.

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.