Skip to main content

Remix API Integration with Nile Database

This guide explains how to integrate Nile Database with Remix and set up routes for handling various HTTP requests (GET, POST, PUT, DELETE). Additionally, you’ll see how to include client-side components for user authentication and interaction using Nile’s React SDK.
1

Create a new Remix project

Run the following command in your terminal to create a new Remix project:
Follow the prompts and install your app. After creating the project, navigate into the newly created project directory:
2

Obtain Database Credentials

  1. If you haven’t signed up for Nile yet, sign up here and follow the steps to create a database.
  2. Navigate to Database Settings in your database’s UI at console.thenile.dev.
  3. Go to Connection settings.
  4. Select the CLI icon, and click Generate credentials Generate credentials
  5. Copy the required credentials and store them in an .env file so they can be used in the application to connect to the Nile auth service.
  6. While you are there, click on the PostgreSQL icon and also copy your database url for drizzle to use
3

Update create-react-router output

Now we must update the output from the default create-react-router for use with Nile. We want to switch to using node-postgres, and be able to do a top level await for nile configuration.
bash
4

Add Nile to the server

Now we need to add the nile instance and route handlers to allow our server to respond to authentication, user, and tenant requests.
Bash
5

Add Client-Side Code for Authentication

You can use the components from @niledatabase/react to handle authentication. Replace the boilerplate of the main _index.tsx file with the following:This component will render:
  • User info and the guest book if the user is signed in.
  • Sign-up form if the user is not signed in.
Bash
6

Running the Project

To run your project, execute the following:
This will start the development server at http://localhost:3000, and you can test your API endpoints and authentication components.

Summary

Now you can interact with your Nile Database through Remix API routes and manage authentication in your app!