Skip to content

Restura Setup From Scratch

This guide will walk you through setting up the infrastructure needed to build REST APIs with Restura. You’ll create an Express application, set up a local PostgreSQL database, install Restura, and connect the Visual Editor.

By the end of this guide, you’ll have:

  • An Express application with Restura integrated
  • A local PostgreSQL database running in Docker
  • The Restura Visual Editor running and connected to your API
  • A complete development environment ready to build REST APIs

This guide teaches you how to:

  1. Create and configure an Express application
  2. Install and initialize Restura
  3. Set up a local PostgreSQL database with Docker
  4. Configure Restura with schema and config files
  5. Connect the Visual Editor to your API
  • Node.js 18+ installed
  • Docker Compose installed
  • Git installed
  • A terminal and text editor
  • Basic knowledge of JavaScript/TypeScript

First, let’s create a new Express project.

Run the following commands in your terminal:

Terminal window
mkdir restura-demo
cd restura-demo
npm init -y
npm install express
Section titled “Install TypeScript (Optional but Recommended)”

If you want to use TypeScript, install it now:

Terminal window
npm install -D typescript @types/express @types/node
npx tsc --init

Create a file called server.ts (or server.js if not using TypeScript):

We’ll add content to this file after installing Restura.

Now install the Restura Engine:

Terminal window
npm install @restura/core

Step 3: Initialize Restura in Your Express App

Section titled “Step 3: Initialize Restura in Your Express App”

Open your server.ts (or server.js) file and add the following code:

server.ts
import { PsqlPool, restura, type OnValidAuthenticationCallback, type RsRequest, type RsResponse } from '@restura/core';
import express from 'express';
const app = express();
// Create a PostgreSQL connection pool
// We'll use these credentials with our Docker setup below
const pool = new PsqlPool({
host: "localhost",
port: 5432,
user: "postgres",
password: "postgres",
database: "restura",
});
// Define an authentication handler
// For now, we'll allow all requests as the 'user' role
const authHandler = async (req: RsRequest<unknown>, res: RsResponse<unknown>, onValid: OnValidAuthenticationCallback) => {
onValid({ role: 'user', scopes: [] });
};
// Initialize Restura
await restura.init(app, authHandler, pool);
app.listen(3001, () => {
console.log('Server is running on http://localhost:3001');
});

Update your package.json to add a start script:

package.json
{
"type": "module",
"scripts": {
"start": "node server.ts"
}
}

Restura needs two configuration files to work.

Create a restura.config.mjs file in your project root:

restura.config.mjs
export default {
logger: {
level: "info" // Options: "debug", "info", "warn", "error"
},
restura: {
authToken: "12345" // Used by the Visual Editor to connect to your API
}
}

Create a restura.schema.json file in your project root.

Add the following content to the file:

restura.schema.json
{
"customTypes": [],
"database": [],
"endpoints": [
{
"baseUrl": "/api/v1",
"description": "V1 Endpoints",
"name": "V1",
"routes": []
}
],
"globalParams": ["userId"],
"roles": ["user"],
"scopes": ["read:user", "write:user"]
}

This creates a minimal schema with an empty database and endpoint structure that the Visual Editor can work with.

For this tutorial, we’ll use Docker Compose to run a local PostgreSQL database.

Create a docker-compose.yml file in the root of your project with the following content:

docker-compose.yml
services:
postgres:
image: postgres:16
ports:
- 5432:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: restura

Then run the following command to start the local PostgreSQL database:

Terminal window
docker compose up -d

The database is now running in the background. The credentials in your server.ts file match this setup, so you’re ready to go!

Now let’s start your API server. Open a terminal and run:

Terminal window
npm start # or pnpm start, yarn start, bun start, etc.

You should see output like:

Terminal window
INFO [2026-01-12 04:25:34.373]: Restura loaded (0) endpoint
INFO [2026-01-12 04:25:34.379]: Restura Engine Initialized
INFO [2026-01-12 04:25:34.495]: Successfully connected to database triggers
INFO [2026-01-12 04:25:34.498]: Connected to PostgreSQL database
Server is running on http://localhost:3001

Keep this terminal running. Your API server needs to be running for the Visual Editor to connect to it.

The Visual Editor is a web application that lets you visually design your database tables and API endpoints.

Once you’ve completed the Visual Editor setup and signed in, you should see an empty dashboard with options to create database tables and endpoints.

Congratulations! You’ve successfully set up your Restura development environment. You now have:

  • ✅ An Express application with Restura integrated
  • ✅ A local PostgreSQL database running
  • ✅ The Visual Editor connected to your API
  • ✅ A complete development environment ready to build REST APIs

Ready to build your first API? Continue to the Build a Blog REST API tutorial to learn how to use the Visual Editor to create database tables and API endpoints.