Skip to content
On this page

CRUD your first Entity

Define an Entity Model Class

Remult entity classes are shared between frontend and backend code.

// shared/product.ts

import { Entity, Fields } from 'remult';

@Entity('products', {
    allowApiCrud: true
export class Product {
    id!: string;

    name = '';

    unitPrice = 0;

Alternatively, generate entities from an existing Postgres database.

Register the Entity on the Server

All Remult server middleware options contain an entities array. Use it to register your Entity.

// backend/index.ts

import express from 'express';
import { remultExpress } from 'remult/remult-express';
import { Product } from '../shared/product';

const app = express();

  entities: [Product]

Query and Mutate data in Front-end code

// frontend/code.ts

import { remult } from 'remult';
import { Product } from '../shared/product';

const productsRepo = remult.repo(Product);

async function playWithRemult() {
    // add a new product to the backend database
    await productsRepo.insert({ name: 'Tofu', unitPrice: 5 });

    // fetch products from backend database
    const products = await productsRepo.find();

    // update product data
    const tofu = products.filter(p => === 'Tofu');
    await{ ...tofu, unitPrice: tofu.unitPrice + 5});

    // delete product
    await productsRepo.delete(tofu);


MIT Licensed | Made by the Remult team with ❤️