Skip to content

pchavanne/nextjs13-natsws

Repository files navigation

Next.js 13 - Nats WebSocket Integration

This Next.js project is bootstrapped with create-next-app and aims to integrate Nats Websocket with Next.js 13.

Getting Started

Before running this project, make sure you have a working NATS server and set up the required environment variables.

Configuring Environment Variables

Create a .env file in the root of your project with the following content:

NATS_SERVERS=<your_nats_server_address>

Then, run the preview server:

npm run preview
# or
yarn preview
# or
pnpm preview
# or
bun preview

⚠️ If you run the dev server you will receive every message twice

Open http://localhost:3000 with your browser to see the result.

You can start sending messages with Nats CLI

nats pub foo "Message N°{{.Count}} on foo" --count=10 --sleep=250ms &
nats pub bar "Message N°{{.Count}} on bar" --count=10 --sleep=250ms &

Releases

No releases published

Packages

No packages published