paint-brush
Nucleoid: A Low-code Framework for Node.jsby@canmingir
1,608 reads
1,608 reads

Nucleoid: A Low-code Framework for Node.js

by Can MingirAugust 9th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Nucleoid low-code framework lets you build your APIs with the help of AI and a built-in datastore. As writing just like any other codes in Node.js, AI inside the runtime rerenders the very same JavaScript codes and makes the necessary adjustments in the state as well as stores them on the disk so that your application doesn't require an external database or anything else. The main objective of the project is to manage both data and logic under the same runtime, at the same time, we can also stream/export data to an external databases like NoSQL.

Coins Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Nucleoid: A Low-code Framework for Node.js
Can Mingir HackerNoon profile picture


We've launched a project that it can automate data and logic in Node.js so that it can organically reduce your code lines.


Nucleoid Low-code Framework works with an underlying declarative runtime environment that re-renders the very same JavaScript codes that make connections in the graph and eventually save the JavaScript state so that it doesn't require an external database.


Features

  • 👽 lets developers build APIs with the help of AI (Lots of Graphs)
  • ❤ works with the underlying declarative runtime environment
  • 🤘 the runtime also comes with a built-in datastore


Hello World

> npm i nucleoidjs


Once installed, you can simply run with Express.js


const nucleoid = require("nucleoidjs");
const app = nucleoid();

class User {
  constructor(name) {
    this.name = name;
  }
}

// 👇 This is it!
app.post("/users", () => {
  new User("Daphne");
});

app.listen(3000);


This is pretty much it, thanks to AI in the runtime, only with this 👆, you successfully persisted your first object without an external database. 😎


Theory

Applying declarative programming at the runtime gives us ability to include data management in the same process.


In different words, the main objective of the project is to manage both data and logic under the same runtime, at the same time, we can also stream/export data to an external database like NoSQL.


CRUD

Quick Setup


const nucleoid = require("nucleoidjs"); // npm install nucleoidjs
const app = nucleoid();


Create

let's start with creating User class and its first user object with this 👇


class User {
  constructor(name) {
    this.name = name;
  }
}

nucleoid.register(User);

app.post("/users", (req) => {
  const name = req.body.name;
  return new User(name);
});


🌵 The reason why you don't need an external database is Nucleoid runtime manages and stores JavaScript state. Every time when there are statements run through the runtime, the Nucleoid runtime adjusts the AI graph and stores it within runtime-managed fs.


Read


app.get("/users/:id", (req) => {
  const id = req.params.id;
  return User[id];
});


When a class like User registered, the runtime creates a shortcut array for its instances, you can query or use the id (var name) of the instance for the access later down. Alternatively, you can do like this too User.find(user => user.id === id)


Update & Delete

app.post("/users/:id", (req) => {
  const id = req.params.id;
  const name = req.body.name;

  const user = User[id];

  if (user) {
    user.name = name;
    return user;
  }
});

app.delete("/users/:id", (req) => {
  const id = req.params.id;
  delete User[id];
});


Similar to the examples above, it works with vanilla JavaScript, and the runtime re-renders and manages the JavaScript state. Additionally, you can write up some business logic in JavaScript as well. For example, you may say if (user.name.length < 3) { throws "INVALID_USER" } if you want certain limitations on users' names.


Query

nucleoidjs the package also opens up a terminal channel in order to run statements like SQL



How it works


nucleoid.run(() => {
  var a = 1;
  var b = a + 2;
  var c = b + 3;
});


Once a variable is defined like var a = 1, the runtime does 3 major things. First, it places the var a in the graph and makes the connection between dependent variables. Variable Graph

Second, update the state with new values in order to get affected

State Table


However, the actual execution is different since variables are tracked in the graph.


state.a = 1;
state.b = state.a + 2;
state.c = state.b + 3;


and finally stores statements in the runtime-managed fs.


OpenAPI Integration with Nucleoid IDE

We are also building an online OpenAPI editor that helps to build up the very same APIs with the user interface. It is specially designed for OpenAPI integration and also has a connection to CodeSandbox so that you can easily run your projects on the sandbox.


IDE Screenshot




Thanks to declarative programming, we have a brand-new approach to data and logic. As we are still discovering what we can do with this powerful programming model, please join us with any type of contribution!


Learn more at https://github.com/NucleoidJS/Nucleoid