CRUD with Nucleoid (Low-code Backend)
Tags: node, javascript, lowcode, ai
Published: 2022-08-02 18:56:18

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

**Features**

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


**Quick Setup**

```javascript
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 :point_down:

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

nucleoid.register(User);

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

:cactus: <u>The reason why you don't need external database</u> is Nucleoid runtime manages and stores JavaScript state. Every time when there are statements run through the runtime, Nucleoid runtime adjusts the AI graph and stores within runtime-managed `fs`.

### Read

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

When a class like `User` registered, the runtime creates <u>shortcut array</u> 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

```javascript
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 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 limitation on users' names.

### Query

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

![Terminal Screenshot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ywdtjyhjd20tl9ejxxg.png)

### Nucleoid IDE (OpenAPI Editor)

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

<img src="https://cdn.nucleoid.com/media/screenshot-1.png" alt="Screenshot 1" width="800" height="480" />

---

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 types of contribution!

<center>
  Learn more at <a href="https://github.com/NucleoidJS/Nucleoid">https://github.com/NucleoidJS/Nucleoid</a>
</center>

[![Nucleoid Logo](https://cdn.nucleoid.com/media/icon.png)](https://nucleoid.com)