Skip to main content
In this guide, we will add a Novu Bridge Endpoint to a NestJS application and send our first test workflow.
1

Set up your local environment

Start the Local Studio by running:
The Local Studio will be available at http://localhost:2022. This is where you can preview and test your workflows.
2

Install packages

Install the Novu Framework package:
This package provides all the necessary tools to build and manage your notification workflows.
3

Add the NovuModule to your application

The NovuModule is a NestJS module that registers the Novu Endpoint in your application.The following example does not support NestJS dependency injection. If you need to @Injectable dependencies in your workflow definition, see Advanced Usage.
src/app.module.ts
4

Configure your secret key

Add your Novu secret key to your environment variables:
.env
5

Create your workflow definition

Add a novu folder in your src folder as such src/novu/workflows.ts that will contain your workflow definitions.
app/novu/workflows.ts
6

Start your application

Start your NestJS application with the Novu Endpoint configured.If your NestJS application is running on other than 4000 port, restart the npx novu dev command with the port:
7

Test your endpoint

Test your workflow by triggering it from the Local Studio or using the Novu API:
You should see the notification being processed in your Local Studio.
8

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:

Advanced Usage (Dependency Injection)

If you need to inject dependencies into your workflow definition, you can use the registerAsync method. Add the NovuModule using the registerAsync method to your AppModule.
src/app.module.ts
For example, you might need to inject a service that fetches the user’s name from a database. This is useful when you need to fetch data in realtime during the execution of your workflow. An example UserService is available below with hardcoded values, but in a real-world application you might use a database or an external API to fetch the user’s name.
src/user.service.ts
Finally, configure your NotificationService to use the injected UserService.
src/notification.service.ts
A full example NestJS application demonstrating dependency injection is available here.