Javascript | V8

The JavaScript functions that Nex executes are run inside a V8 sandbox, which is inside a Firecracker sandbox. As a result, these JavaScript functions don't have the same kind of freedom of access to capabilities that other function types (e.g. Node.js in a cloud provider). However, we've made the most common use cases available by default through what we call "host services"

Host services aren't just access to arbitrary capabilities, they're access to managed capabilities that are designed to be pre-provisioned and ready to go, so function developers don't have to write provisiong code, they can focus solely on the abstractions of capabilities they need.

HTTP Client

If you want to make HTTP calls from your function, you can do so with the HTTP client:

get = this.hostServices.http.get('');

All of the HTTP methods are supported as functions:

  • get

  • post

  • put

  • patch

  • del

  • head

Key-Value Store

Every Nex-managed JavaScript function has access to an abstraction over a key-value store, which is internally backed by a NATS Key-Value bucket.

this.hostServices.kv.set('hello', payload);

this.hostServices.kv.set('hello2', payload);
return {
  keys: this.hostServices.kv.keys(),
  hello2: this.hostServices.kv.get('hello2')

Again, note that you don't have to manually or explicitly provision the bucket. You can assume that your function has its own, isolated bucket and that it is safe in a multi-tenant environment.

Object Store

The object store is still under construction

Core Messaging

JavaScript functions receive messages on their trigger subjects, which are specified at deployment time. To publish or make requests, host services provides access to a core NATS black box.

this.hostServices.messaging.publish('', payload);

req = this.hostServices.messaging.request('', payload);

reqMany = this.hostServices.messaging.requestMany('', payload);

Last updated