---
source_url: https://www.pubnub.com/docs/sdks/javascript/api-reference/misc
title: Utility Methods API for JavaScript SDK
updated_at: 2026-06-19T11:37:31.870Z
sdk_name: PubNub JavaScript SDK
sdk_version: 11.0.2
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Utility Methods API for JavaScript SDK

PubNub JavaScript SDK, use the latest version: 11.0.2

Install:

```bash
npm install pubnub@11.0.2
```

The methods on this page are utility methods that don't fit into other categories.

## PubNubFile

Internal representation of the file used by the SDK. Depending on the environment, different methods can be used to extract the file.

### Extracting the file

##### Methods supported in Node.js

* `file.toBuffer()` returns `Promise<Buffer>`
* `file.toStream()` returns `Promise<Readable>`
* `file.toString(encoding: string)` returns a string encoded using `encoding` (if not available, defaults to `utf8`)

##### Methods supported in a browser

* `file.toFile()` returns `Promise<File>`
* `file.toBlob()` returns `Promise<Blob>`
* `file.toArrayBuffer()` returns `Promise<ArrayBuffer>`
* `file.toString(encoding: string)` returns a string encoded using `encoding` (if not available, defaults to `utf8`)

##### React and React Native

* `file.toBlob()` returns `Promise<Blob>`

### Creating a file

```javascript
pubnub.File.create(input: FileInput): PubNubFile;
```

`FileInput` represents a variety of possible inputs that represent a file in different environments.

#### Node.js

* Using streams: 1{2 stream: Readable,3 name: string,4 mimeType?: string5}
* Using buffers: 1{2 data: Buffer,3 name: string,4 mimeType?: string5}
* Using strings: 1{2 data: string,3 encoding: string,4 name: string,5 mimeType?: string6}

#### Browsers

* Using File API: 1File
* Using strings: 1{2 data: string,3 name: string,4 mimeType?: string5}
* Using ArrayBuffer: 1{2 data: ArrayBuffer,3 name: string,4 mimeType?: string5}

## Disconnect

Call the `disconnect` method to stop all requests to PubNub server when there are active subscribe channels.

### Method(s)

To `disconnect` the data transmission you can use the following method(s) in JavaScript SDK.

```javascript
disconnect()
```

This method doesn't take any arguments.

### Sample code

```javascript
pubnub.disconnect();
```

## Reconnect

Call the `reconnect` method to force the SDK to try and reach out PubNub.

### Method(s)

To `reconnect` the data, you can use the following method(s) in JavaScript SDK.

```javascript
reconnect()
```

This method doesn't take any arguments.

### Sample code

```javascript
pubnub.reconnect();
```

## setProxy

Call `setProxy()` to instruct the SDK to assign or reassign a proxy configuration in run time. This method is only available for NodeJS.

### Method(s)

To `setProxy` the data you can use the following method(s) in Node.js SDK.

```javascript
setProxy({String hostname, Number port, String protocol})
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| hostname | String | Yes |  | Specifies the `IP address` the or URI to use. |
| port | Number | Yes |  | Specifies the `port` which the proxy will be listened. |
| protocol | String | Optional | `http` | Supported Protocols are `http`, `https`, `socks5`, `socks4` and `pac`. |

### Sample code

```javascript
// This method is only available for NodeJS.
pubnub.setProxy({
  hostname: 'YOUR_HOSTNAME',
  port: 8080,
  protocol: 'YOUR_PROTOCOL',
});
```

### Other examples

#### Delete the proxy in run time

```javascript
pubnub.setProxy();
```

## Terms in this document

* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.