Skip to main content

In this guide, we will add a Novu Bridge Endpoint to a Next.js application and send our first test workflow.

Create a Next.js application

This link can be copied right from the onboarding guide on the Novu Dashboard or can always be copied from the API Keys page on the Novu Dashboard.

The sample application will create an .env file containing the NOVU_SECRET_KEY environment variable required for securing your endpoint. And a sample workflow demonstrating the flexibility of Novu using Step Controls.

Manually add to an existing application (5 minutes)

Install required packages

This will install

  • @novu/framework SDK Package
  • React Email (Recommended) - For writing your email templates with React
  • Zod (Recommended) - For end-to-end type safety for your Payload and Step Controls

Add a Novu API Endpointt

App Router (app/api/novu/route.ts)
Pages Router (pages/api/novu.ts)

Add a Novu Secret Key Environment Variable

Add NOVU_SECRET_KEY environment variable to your .env

Create your workflow definition

Add a novu folder that will contain your workflow definitions

app/novu/workflows.ts

Create your React Email Template (Optional)

Add a new email template

app/novu/emails/test-email.tsx

Start your application#

To start your boilerplate Next.js server with the Novu Endpoint configured, run the following command:

The sample application will start on https://localhost:4000 and your novu endpoint will be exposed at /api/novu served by the Next.js API.

If your Next.js application is running on other than 4000 port, restart the novu dev command with the port:

Test your endpoint#

Test your workflow by triggering it from the Local environment or using the Novu API:

You should see the notification being processed in the Local environment.

Deploy your application#

Deploy your application to your preferred hosting provider. Make sure the /api/novu endpoint is accessible from the internet.

For local development and testing, you can use tools like ngrok to expose your local server to the internet.

Now that you have your first workflow running, you can: