PYTHON HELP

deepstream io (How it Works for Developers)

A real-time server is designed to respond to data instantly, making it instantly responsive to every user interaction or system event. Unlike conventional request-response servers that introduce delays, real-time servers use technologies and protocols to ensure continuous information exchange and instantaneous updates. It's because a real-time server is critical to several applications requiring live communications: messaging systems, online gaming, financial trading platforms, and collaborative tools. In this article, we are going to learn how to use the open realtime server deepstream and IronPDF to generate PDFs.

deepstream.io is a scalable, real-time server for data synchronization and many-to-many messaging. It can handle data with ease and keep many clients synchronized with really low latency, supporting binary data transfer. deepstream.io is designed to be put behind other load balancing and balancers and offers an efficient way to sync data and keep resource files up to date, which makes it perfectly suited for applications updating data in real-time and in search of a scalable server solution.

deepstream io (How it Works for Developers): Figure 1 - deepstream.io

deepstream.io implementation by developers can easily allow live updates, collaborative applications, and interactive experiences in real-time, without starting from scratch. It has been architected for high loads and efficient scaling, making it the software of choice for high-concurrency applications. deepstream.io is flexible and may turn out to be the perfect addition to your stack in multiple different ways. It provides a complete solution to allow users to create real-time, responsive, and interactive web and mobile apps.

To create a new Node.js directory enter the following commands in the console:

mkdir deepstream-project
cd deepstream-project
npm init -y
mkdir deepstream-project
cd deepstream-project
npm init -y
SHELL

Install deepstream.io Package

First of all, you need to install deepstream.io. You can either use NPM to install it or download the binaries from the official website.

npm install @deepstream/server
npm install @deepstream/server
SHELL

Basic Configuration of deepstream.io

const { Deepstream } = require('@deepstream/server');

// Create a new Deepstream server instance
const server = new Deepstream({});

// Start the server to listen for client connections
server.start();
const { Deepstream } = require('@deepstream/server');

// Create a new Deepstream server instance
const server = new Deepstream({});

// Start the server to listen for client connections
server.start();
JAVASCRIPT

The code snippet above demonstrates how to set up and start a deepstream.io server using the @deepstream/server package in Node.js. It first imports the Deepstream class from the package, then creates a new instance. By calling server.start(), the server is started and is ready to accept incoming connections for handling real-time data binding, messaging, or presence backend services.

Connecting Deepstream with Client

const { DeepstreamClient } = require('@deepstream/client');

// Connect to a local deepstream server
const client = new DeepstreamClient('127.0.0.1:6020');

// Log in to the server without credentials (suitable for servers without authentication)
client.login(null);
const { DeepstreamClient } = require('@deepstream/client');

// Connect to a local deepstream server
const client = new DeepstreamClient('127.0.0.1:6020');

// Log in to the server without credentials (suitable for servers without authentication)
client.login(null);
JAVASCRIPT

The code above demonstrates how to connect to deepstream using the @deepstream/client library. This script imports the DeepstreamClient class, creates an instance, and connects it to a deepstream server running locally on IP address 127.0.0.1 on port 6020. It logs in without credentials, which is sufficient if the server does not use authentication or if it's used for test cases. This setup initializes a client capable of real-time data synchronization and communication.

Once the connection with the server node is established, a message similar to the one below will appear in the server console.

deepstream io (How it Works for Developers): Figure 2 - Console Message

Using Listener with deepstream.io

Below is a sample code which can be used to create listeners, one of the core concepts of deepstream.

const { DeepstreamClient } = require("@deepstream/client");

// Connect to the Deepstream server
const client = new DeepstreamClient("127.0.0.1:6020");

// Log in to the server
client.login(null, (success, clientData) => {
  if (success) {
    const event = client.event;
    // Publish a custom event
    event.publish("custom-event", { message: "Hello, Deepstream!" });
  }
});
const { DeepstreamClient } = require("@deepstream/client");

// Connect to the Deepstream server
const client = new DeepstreamClient("127.0.0.1:6020");

// Log in to the server
client.login(null, (success, clientData) => {
  if (success) {
    const event = client.event;
    // Publish a custom event
    event.publish("custom-event", { message: "Hello, Deepstream!" });
  }
});
JAVASCRIPT

In the above code, the client logs into a deepstream server hosted on 127.0.0.1:6020 using the @deepstream/client library. Upon successful authentication, it publishes a custom event named "custom-event" with a payload { message: "Hello, Deepstream!" }.

Introducing IronPDF

Use IronPDF, an incredibly strong Node.js package, to create, edit, convert, and edit PDF documents. It is a tool used in the majority of programming-based processes on PDFs, and backend processes such as modifying pre-existing PDFs and converting HTML into PDFs. In applications where the dynamic creation and handling of PDFs are necessary, IronPDF becomes very helpful. It provides a user-friendly and flexible manner in which to generate quality PDF documents.

deepstream io (How it Works for Developers): Figure 3 - IronPDF

Install IronPDF package

Use npm to download and install packages that enable Node.js IronPDF capability.

npm install @ironsoftware/ironpdf
npm install @ironsoftware/ironpdf
SHELL

PDF Generation Function

Create a function that uses IronPDF to generate PDFs:

const IronPdf = require('@ironsoftware/ironpdf');
const { PdfDocument } = IronPdf;

// Set IronPDF configuration, replacing 'YOUR_LICENSE_KEY' with your actual license key
const config = IronPdf.IronPdfGlobalConfig;
config.setConfig({ licenseKey: 'YOUR_LICENSE_KEY' });

async function generatePDF(title, content) {
  try {
    // Generate PDF from HTML content
    const pdf = await PdfDocument.fromHtml(`<html><body><h1>${title}</h1><p>${content}</p></body></html>`);
    return await pdf.saveAsBuffer();
  } catch (error) {
    console.error('Error generating PDF:', error);
    throw error;
  }
}

module.exports = generatePDF;
const IronPdf = require('@ironsoftware/ironpdf');
const { PdfDocument } = IronPdf;

// Set IronPDF configuration, replacing 'YOUR_LICENSE_KEY' with your actual license key
const config = IronPdf.IronPdfGlobalConfig;
config.setConfig({ licenseKey: 'YOUR_LICENSE_KEY' });

async function generatePDF(title, content) {
  try {
    // Generate PDF from HTML content
    const pdf = await PdfDocument.fromHtml(`<html><body><h1>${title}</h1><p>${content}</p></body></html>`);
    return await pdf.saveAsBuffer();
  } catch (error) {
    console.error('Error generating PDF:', error);
    throw error;
  }
}

module.exports = generatePDF;
JAVASCRIPT

Set Up the Deepstream Client

Write a JavaScript script that will listen for data in real-time and generate PDFs based on that data:

const { DeepstreamClient } = require('@deepstream/client');
const generatePDF = require('./generatePdf'); // Path to your PDF generation function

// Connect to the Deepstream server
const client = new DeepstreamClient('127.0.0.1:6020');

// Log in to the server
client.login(null, async (success) => {
  if (success) {
    console.log('Deepstream connected successfully');
    // Listen for a custom event to trigger PDF generation
    const event = client.event;
    event.subscribe('generate-pdf', async (data) => {
      const { title, content } = data;
      if (!title || !content) {
        console.error('Missing title or content for PDF generation');
        return;
      }
      try {
        // Generate the PDF
        const pdfBuffer = await generatePDF(title, content);
        // Handle the PDF buffer (e.g., save to file, send over network)
        console.log('PDF generated successfully');
        // Example: Save PDF to a file (optional)
        const fs = require('fs');
        fs.writeFileSync('generated.pdf', pdfBuffer);
      } catch (error) {
        console.error('Error generating PDF:', error);
      }
    });
  } else {
    console.error('Failed to connect to Deepstream');
  }
});
const { DeepstreamClient } = require('@deepstream/client');
const generatePDF = require('./generatePdf'); // Path to your PDF generation function

// Connect to the Deepstream server
const client = new DeepstreamClient('127.0.0.1:6020');

// Log in to the server
client.login(null, async (success) => {
  if (success) {
    console.log('Deepstream connected successfully');
    // Listen for a custom event to trigger PDF generation
    const event = client.event;
    event.subscribe('generate-pdf', async (data) => {
      const { title, content } = data;
      if (!title || !content) {
        console.error('Missing title or content for PDF generation');
        return;
      }
      try {
        // Generate the PDF
        const pdfBuffer = await generatePDF(title, content);
        // Handle the PDF buffer (e.g., save to file, send over network)
        console.log('PDF generated successfully');
        // Example: Save PDF to a file (optional)
        const fs = require('fs');
        fs.writeFileSync('generated.pdf', pdfBuffer);
      } catch (error) {
        console.error('Error generating PDF:', error);
      }
    });
  } else {
    console.error('Failed to connect to Deepstream');
  }
});
JAVASCRIPT

Publishing Events to Trigger PDF Generation

Events can be published to trigger PDF generation from another JavaScript file or part of your application:

const { DeepstreamClient } = require('@deepstream/client');

// Connect to the Deepstream server
const client = new DeepstreamClient('127.0.0.1:6020');

// Log in to the server
client.login(null, () => {
  const event = client.event;
  // Publish a custom event with title and content
  event.publish('generate-pdf', {
    title: 'Sample PDF Title',
    content: 'This is the content of the PDF document.'
  });
});
const { DeepstreamClient } = require('@deepstream/client');

// Connect to the Deepstream server
const client = new DeepstreamClient('127.0.0.1:6020');

// Log in to the server
client.login(null, () => {
  const event = client.event;
  // Publish a custom event with title and content
  event.publish('generate-pdf', {
    title: 'Sample PDF Title',
    content: 'This is the content of the PDF document.'
  });
});
JAVASCRIPT

Deepstream.io is implemented by listening to real-time events that will trigger the PDF generation. The generatePDF function creates a PDF document based on data from Deepstream.io events using IronPDF. The DeepstreamClient subscribes to these events, and whenever relevant events are published, it calls the PDF generation function. Such integration allows the dynamic generation of PDFs in real-time based on event occurrences, requests, or data changes.

deepstream io (How it Works for Developers): Figure 4 - PDF Output

Licensing

For the code to compile and function without a watermark, a licensing key is required. Developers who would like a trial license can register here. Obtaining one does not need presenting a credit card. All you have to do to sign up for a free trial is enter your email address.

Conclusion

One of the strongest real-time data handling and dynamic document generation solutions is achieved through a combination of deepstream.io and IronPDF. deepstream.io synchronizes changes and records all events in real-time, thus it can react right away to any change in data. IronPDF provides a robust mechanism for creating professional documents on the fly. This integration will enable your applications to automatically create and process PDF documents not only when live data changes but also whenever a user interacts with your application.

Whether it's report generation, invoices, or any other document type, deepstream.io integrated with IronPDF enables workflow simplification, responsive document creation, and keeps your application lean and current with real-time information. This pairing works best for agile, data-driven, and responsive applications that demand real-time document generation and management support.

The libraries provided by Iron Software enable us to create programs quickly and easily for a variety of operating systems, browsers, and platforms, including Windows, Android, MAC, Linux, etc.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.
NEXT >
imageio python (How it Works for Developers)

Ready to get started? Version: 2025.6 just released

View Licenses >