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.
What You’ll Build
Section titled “What You’ll Build”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
What You’ll Learn
Section titled “What You’ll Learn”This guide teaches you how to:
- Create and configure an Express application
- Install and initialize Restura
- Set up a local PostgreSQL database with Docker
- Configure Restura with schema and config files
- Connect the Visual Editor to your API
Prerequisites
Section titled “Prerequisites”- Node.js 18+ installed
- Docker Compose installed
- Git installed
- A terminal and text editor
- Basic knowledge of JavaScript/TypeScript
Step 1: Create an Express Application
Section titled “Step 1: Create an Express Application”First, let’s create a new Express project.
Create a new project directory
Section titled “Create a new project directory”Run the following commands in your terminal:
mkdir restura-democd restura-demonpm init -ynpm install expressmkdir restura-democd restura-demopnpm initpnpm add expressmkdir restura-democd restura-demoyarn init -yyarn add expressmkdir restura-democd restura-demobun init -ybun add expressInstall TypeScript (Optional but Recommended)
Section titled “Install TypeScript (Optional but Recommended)”If you want to use TypeScript, install it now:
npm install -D typescript @types/express @types/nodenpx tsc --initpnpm add -D typescript @types/express @types/nodepnpx tsc --inityarn add -D typescript @types/express @types/nodeyarn tsc --initbun add -D @types/expressCreate an entry file
Section titled “Create an entry file”Create a file called server.ts (or server.js if not using TypeScript):
We’ll add content to this file after installing Restura.
Step 2: Install Restura
Section titled “Step 2: Install Restura”Now install the Restura Engine:
npm install @restura/corepnpm add @restura/coreyarn add @restura/corebun add @restura/coreStep 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:
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 belowconst 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' roleconst authHandler = async (req: RsRequest<unknown>, res: RsResponse<unknown>, onValid: OnValidAuthenticationCallback) => { onValid({ role: 'user', scopes: [] });};
// Initialize Resturaawait restura.init(app, authHandler, pool);
app.listen(3001, () => { console.log('Server is running on http://localhost:3001');});const { PsqlPool, restura } = require('@restura/core');const express = require('express');
const app = express();
// Create a PostgreSQL connection pool// We'll use these credentials with our Docker setup belowconst 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' roleconst authHandler = async (req, res, onValid) => { onValid({ role: 'user', scopes: [] });};
// Initialize Restura(async () => { await restura.init(app, authHandler, pool);
app.listen(3001, () => { console.log('Server is running on http://localhost:3001'); });})();Add a start script
Section titled “Add a start script”Update your package.json to add a start script:
{ "type": "module", "scripts": { "start": "node server.ts" }}{ "scripts": { "start": "node server.js" }}Step 4: Create Configuration Files
Section titled “Step 4: Create Configuration Files”Restura needs two configuration files to work.
Create restura.config.mjs
Section titled “Create restura.config.mjs”Create a restura.config.mjs file in your project root:
export default { logger: { level: "info" // Options: "debug", "info", "warn", "error" }, restura: { authToken: "12345" // Used by the Visual Editor to connect to your API }}Create an empty schema file
Section titled “Create an empty schema file”Create a restura.schema.json file in your project root.
Add the following content to the file:
{ "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.
Step 5: Setup a Local PostgreSQL Database
Section titled “Step 5: Setup a Local PostgreSQL Database”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:
services: postgres: image: postgres:16 ports: - 5432:5432 environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: resturaThen run the following command to start the local PostgreSQL database:
docker compose up -dThe database is now running in the background. The credentials in your server.ts file match this setup, so you’re ready to go!
Step 6: Start Your Restura API
Section titled “Step 6: Start Your Restura API”Now let’s start your API server. Open a terminal and run:
npm start # or pnpm start, yarn start, bun start, etc.You should see output like:
INFO [2026-01-12 04:25:34.373]: Restura loaded (0) endpointINFO [2026-01-12 04:25:34.379]: Restura Engine InitializedINFO [2026-01-12 04:25:34.495]: Successfully connected to database triggersINFO [2026-01-12 04:25:34.498]: Connected to PostgreSQL databaseServer is running on http://localhost:3001Keep this terminal running. Your API server needs to be running for the Visual Editor to connect to it.
Step 7: Setup the Visual Editor
Section titled “Step 7: Setup the Visual Editor”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.
What’s Next?
Section titled “What’s Next?”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.