Jexia and JS

Get to know all the basic pieces of code to get the advantage of Jexia through JavaScript. All the following code examples use Jexia Javascript SDK. This is the official JavaScript / TypeScript SDK for interacting with Jexia projects.

Install for NodeJs

With NodeJs you will need to install node-fetch and ws dependencies:

npm install jexia-sdk-js node-fetch ws --save

Install for Web browser

npm install jexia-sdk-js --save


To use dataset features, just add dataOperations module to the client initialization. Notice, that for Node.js you have to import dataOperations from jexia-sdk-js/node, but if you are running your application in a browser, you should import it from jexia-sdk-js/browser.

import { jexiaClient, dataOperations } from "jexia-sdk-js/node"; // "jexia-sdk-js/browser" for browser applications

const dataModule = dataOperations();

  projectID: "<your-project-id>",
  key: "<your-project-api-key>",
  secret: "<your-project-api-secret>",
}, dataModule);

There is an option to have access via User management system instead of API. For this you need to create at least 1 user, policy for AllUsers. As well you need to import UMS module. With example below you can inititate Jexia and select all records which is elligable for

import { jexiaClient, dataOperations, UMSModule} from "jexia-sdk-js/node"; // "jexia-sdk-js/browser" for browser applications

const dom = dataOperations();

  projectID: "your-project-id"
}, dom, ums);

  email: '',  
  password: 'user-password',  
  default: true


Currently, SDK is focused on consuming data. You can execute the following operations on records:

  • READ

Executing an operation on a set of records is done through a Query. Depending on their type, Queries give the user access to some (or all) of the following options:

  • Filtering (only records satisfying a certain condition will be retrieved/affected).
  • Sorting (the records will be sorted by a rule and direction before the action is executed).
  • Limiting/offsetting (only a certain number of records, starting from a certain position in the Dataset will be affected).
  • Selecting the fields to be retrieved (when the user does not want the entire record to be retrieved, only certain columns).

It is important to notice that all these features are handled server-side. More you can get on JS SDK documentation page 

Inserting records

Records can be inserted to a dataset either by sending an array or a single one. The response will always be an array though.

const posts = dataModule.dataset("posts");  
const insertQuery = posts.insert([  
 { title: "New Post", content: "content here" }, 
 { title: "Another Post", content: "some more content" }

// At this point nothing has happened yet 
// we need to call subscribe in order to run a query
// Single record  
const insertQuery = posts.insert({  
 title: "New Post", content: "content here"
// Either way, the response will be an array  
insertQuery.subscribe(records => { 
     // you will always get an array of created records, including their generated IDs (even when inserting a single record) 
  error => { 
     // you can see the error info here, if something goes wrong 

Updating records

The update method is used to modify records, it always has to be used with the .where method and a filter criteria.

const posts = dataModule.dataset("posts"); 

  .update({ title: "Same title for tom and harry posts" }) 
  .where(field => field("author_name").isInArray(["Tom", "Harry"]))
  .subscribe(affectedRecords => {
   /* [{ title: "Same title for tom and harry posts", author_name: "Tom" },       
       { title: "Same title for tom and harry posts", author_name: "Tom" },   
       { title: "Same title for tom and harry posts", author_name: "Harry" },
       { title: "Same title for tom and harry posts", author_name: "Tom" }]   

Deleting records

The delete method is used to delete records, it always has to be used with the .where method and a filter criteria. It is done in this way to avoid accidental deletion of all records from your DataSet:

const posts = dataModule.dataset("posts");

  .where(field => field("title").isLike("%test%"))
  .subscribe(deletedFields => {  
    // you will be able to access the deleted posts here  
    // they are not stored in the DB anymore, but maybe you 
    // want to display a visual confirmation of what was deleted

Only retrieving certain fields

You can use .fields method to restrict fields you want to retrieve.

import { jexiaClient, dataOperations, field } from 'jexia-sdk-js/browser'
const posts = dataModule.dataset("posts");
  .fields("title", "author") // you can also pass an array of field names 
  .subscribe(records => // you will get array of {id, title, author} records (id is always returned));

Filtering records

You can use the filtering to select what records a certain query will operate on.

In order to define a filter, you can use the exposed method field.

import { field } from "jexia-sdk-js/node";  
const isAuthorTom = field("author_name").isEqualTo("Tom");  
const isAuthorDick = field("author_name").isEqualTo("Dick");  
const isAuthorTomOrDick = isAuthorTom.or(isAuthorDick);  
// In order to use these conditions, they need to be added to a query through `.where` method  
 .subscribe(records => // posts of Tom and Dick); 


more datails you can get from JS SDK documentation

our npm module can be found in npmjs