> ## Documentation Index
> Fetch the complete documentation index at: https://thenile.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Installation

> Install nile-auth in your application

<Steps>
  <Step title="Install packages">
    <CodeGroup>
      ```bash npm theme={null}
        npm install @niledatabase/server @niledatabase/client
      ```

      ```bash yarn theme={null}
        yarn add @niledatabase/server @niledatabase/client
      ```

      ```bash pnpm theme={null}
        pnpm add @niledatabase/server @niledatabase/client
      ```
    </CodeGroup>
  </Step>

  <Step title="Obtain Database Credentials">
    1. If you haven't signed up for Nile yet, [sign up here](https://console.thenile.dev) and follow the steps to create a database.
    2. Navigate to **Database Settings** in your database's UI at [console.thenile.dev](https://console.thenile.dev).
    3. Go to **Connection** settings.
    4. Select the CLI icon, and click **Generate credentials**
           <img src="https://mintcdn.com/nile/6B-b9nH3DSiJ_Uwi/images/auth/generate-credentials.png?fit=max&auto=format&n=6B-b9nH3DSiJ_Uwi&q=85&s=f9f160a368eccc6ed7f033a4453aaeee" alt="Generate credentials" width="2020" height="898" data-path="images/auth/generate-credentials.png" />
    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.
       ```bash .env theme={null}
       NILEDB_USER=niledb_user
       NILEDB_PASSWORD=niledb_password
       NILEDB_API_URL=https://us-west-2.api.thenile.dev/v2/databases/<database_id>
       NILEDB_POSTGRES_URL=postgres://us-west-2.db.thenile.dev:5432/<database_name>
       ```
  </Step>

  <Step title="Import and configure the nile-auth instance">
    <CodeGroup>
      ```ts nextjs theme={null}
      import { Nile } from '@niledatabase/server';
      import { nextJs } from '@niledatabase/nextjs';
      export const nile = Nile({ extensions: [nextJs] });
      ```

      ```ts remix theme={null}
      import { Nile } from '@niledatabase/server';
      export const nile = Nile();
      ```

      ```ts express theme={null}
      import { Nile } from '@niledatabase/server';
      import { express } from '@niledatabase/express';
      export const nile = Nile({ extensions: [express(app)] });
      ```

      ```ts nitro theme={null}
      import { Nile } from '@niledatabase/server';
      import { nitro } from '@niledatabase/nitro ';
      export const nile = Nile({ extensions: [nitro] });
      ```

      ```ts JS theme={null}
      import { Nile } from '@niledatabase/server';
      export const nile = Nile();
      ```
    </CodeGroup>
  </Step>

  <Step>
    To handle requests, set up a route handler on your server.

    <CodeGroup>
      ```ts next-js theme={null}
      // app/api/[...nile]/route.ts
      import { nile } from "@/nile"; // path to nile instance
      export const { POST, GET, DELETE, PUT } = nile.handlers;
      ```

      ```ts remix theme={null}
      // app/routes/api.$.ts`
      import type { LoaderFunctionArgs, ActionFunctionArgs } from "@remix-run/node"
      import { nile } from "~/nile"; // the nile instance

      export const loader = async ({ request }: LoaderFunctionArgs) => {
        const method = request.method.toUpperCase();
        return nile.handlers[method](request)
      };

      export const action = async ({ request }: ActionFunctionArgs) => {
        const method = request.method.toUpperCase();
        return nile.handlers[method](request)
      };
      ```

      ```ts express theme={null}
      // server.ts
      import { Nile } from "@niledatabase/server";
      import { express } from "@niledatabase/express";
      const nile = Nile({ extensions: [express(app)] });
      ```

      ```ts nitro theme={null}
      import { nile } from "~/nile"; // the nile instance
      import { convertToRequest } from '@niledatabase/nitro'
       
      export default defineEventHandler((event) => {
          return convertToRequest(event, nile);
      });
      ```

      ```ts JS theme={null}

      async function startServer(req, res) {
      try {
      const method = req.method?.toUpperCase() as 'GET' | 'POST' | 'PUT' | 'DELETE';

          if (!method || !nile.handlers[method]) {
            res.writeHead(405, { 'Content-Type': 'text/plain' });
            return res.end('Method Not Allowed');
          }

          const url = `http://${req.headers.host}${req.url}`;
          const bodyChunks: Uint8Array[] = [];

          req.on('data', chunk => bodyChunks.push(chunk));
          req.on('end', async () => {
            const body = Buffer.concat(bodyChunks);
            const request = new Request(url, {
              method,
              headers: req.headers as HeadersInit,
              body: method === 'POST' || method === 'PUT' ? body : undefined,
            });

            let response;
            try {
              response = await nile.handlers[method](request);
            } catch (err) {
              console.error(err);
              res.writeHead(500, { 'Content-Type': 'text/plain' });
              return res.end('Internal Server Error');
            }

            res.writeHead(response.status, Object.fromEntries(response.headers.entries()));
            const respBody = await response.text();
            res.end(respBody);
          });

      } catch (err) {
      console.error(err);
      res.writeHead(500, { 'Content-Type': 'text/plain' });
      res.end('Unexpected Server Error');
      }
      };

      ```
    </CodeGroup>
  </Step>

  <Step title="Call APIs with the nile-auth client">
    ```ts nile-client.ts theme={null}
    import { getSession, signUp } from '@niledatabase/client'
    ```
  </Step>
</Steps>

With that, you've successfully set up nile-auth in your application.

Continue on to [Social providers](../singlesignon/discord), or check out how to [integrate into specific frameworks](/auth/frameworks/nextjs)
