Setting up the Reveal SDK Server with NestJS
Setting up Reveal SDK with NestJS
This guide will walk you through integrating the Reveal SDK into a NestJS project. Follow the steps below to add powerful data analytics capabilities to your NestJS server.
Step 1 - Create a NestJS Project
- First, install the NestJS CLI globally if you haven't already:
npm install -g @nestjs/cli
- Create a new project by running the following command:
nest new reveal-nest-server
- Change the command line path to the newly created project directory:
cd reveal-nest-server
Step 2 - Install the Reveal SDK
- Inside the NestJS project directory, install the Reveal SDK for Node.js:
- npm
- Yarn
- pnpm
npm install reveal-sdk-node
yarn add reveal-sdk-node
pnpm add reveal-sdk-node
Step 3 - Modify the main.ts
File
To integrate the Reveal SDK, we will modify the main.ts
file directly, where we will enable CORS and add the Reveal SDK routes.
-
Open the
src/main.ts
file. -
Update the
bootstrap
function to configure the Reveal SDK:
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import reveal from 'reveal-sdk-node';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors(); // DEVELOPMENT only! In production, configure appropriately.
app.use("/", reveal());
// Start the server
await app.listen(process.env.PORT ?? 5111);
console.log(`Reveal SDK server running on http://localhost:${process.env.PORT ?? 5111}`);
}
bootstrap();
This setup will configure the Reveal SDK to handle routes under /
. The CORS policy is also enabled globally to allow requests from other origins.
You may need to set "esModuleInterop": true,
in the tsconfig.json file.
Step 4 - Create the Dashboards Folder
Reveal SDK expects dashboard files to be stored in a folder named dashboards in your working directory.
- In your project’s root directory, create a folder named
dashboards
.
mkdir dashboards
You can store any Reveal dashboards in this folder, and they will be accessible through the server. If you need to change this behavior, you can create a custom IRVDashboardProvider
.
Step 5 - Run the NestJS Server
- Start the NestJS server by running the following command:
npm run start
Alternatively, if you're in development mode, run the server with live-reload enabled:
npm run start:dev
Now, your NestJS server is running, and the Reveal SDK is ready to handle requests at http://localhost:5111/
.
The source code to this sample can be found on GitHub.