---
source_url: https://www.pubnub.com/docs/sdks/angular2/api-reference/configuration
title: Configuration API for Angular2 SDK
updated_at: 2026-06-22T06:36:58.195Z
---

> 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


# Configuration API for Angular2 SDK

Angular2 complete Application Programming Interface (API) reference for building real-time applications on PubNub, including basic usage and sample code. This guide explains how to configure and use the Angular2 Software Development Kit (SDK).

## Initialization

**PubNub** Angular2 is a wrapper for the PubNub JavaScript SDK that simplifies integration with Angular v2 and v4.

* Support: Works with TypeScript or plain JavaScript.
* Events: Delegate methods accept the `triggerEvents` option, which broadcasts certain callbacks and binds them directly to the HTML.
* Autoload: Quickly retrieve history messages from a channel.
* Multiple instance behavior: Access all instances throughout the application via the PubNub service.

You can also use the native PubNub JavaScript SDK if it is more suitable for your situation.

### How to use PubNubAngular for Angular4

```bash
npm install --save pubnub pubnub-angular2
```

There are two ways to register **PubNubAngular** in your list of providers in your Angular App: `ngModules` or `ngComponents`.

#### Using your ngModule

Angular Module lets you to use the same instance of **PubNub** in all Angular Components declared in this. Then you will not need to register **PubNub** in any Angular Component hosted by the Angular Module.

```javascript
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { PubNubAngular } from 'pubnub-angular2';
import { AppComponent } from './appComponent';
@NgModule({
    imports:[ BrowserModule ],
    declarations:[ AppComponent ],
    providers:[ PubNubAngular ],
    bootstrap:[ AppComponent ]
})
export class AppModule {
    constructor() {}
}
```

Angular Component only lets you use the same instance of **PubNub** inside itself and its Angular Components children. For more information about this, refer to [Dependency Injection](https://angular.io/guide/dependency-injection) and [Hierarchical Dependency Injectors](https://angular.io/guide/hierarchical-dependency-injection)

```javascript
import { Component } from '@angular/core';
import { PubNubAngular } from 'pubnub-angular2';
@Component({
    selector: 'appComponent',
    template: '<H1>PubNub Angular2 SDK Demo</H1>',
    providers:[ PubNubAngular ]
})
export class AppComponent {
    constructor() {}
}
```

Now, you can inject PubNubAngular into your ngComponents

:::note
Always set the `UUID` to uniquely identify the user or device that connects to PubNub. This `UUID` should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the `UUID` can significantly impact your billing if your account uses the [Monthly Active Users (MAUs)](https://www.pubnub.com/pricing/) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
:::

```javascript
import { Component } from '@angular/core';
import { PubNubAngular } from 'pubnub-angular2';
@Component({
    selector: 'appComponent',
    template: '<H1>PubNub Angular2 SDK Demo</H1>'
})
export class AppComponent {
    constructor(pubnub: PubNubAngular) {
    pubnub.init({
        publishKey: 'YOUR PUB_KEY',
        subscribeKey: 'YOUR SUB_KEY'
        });
    }
}
```

### How to use PubNubAngular for Angular2

For Angular2 you have to add some extra steps in order to setup the environment. Your HTML page will have to include the following libraries:

* Global dependencies for Angular2
* Angular2
* PubNub JavaScript SDK
* PubNub Angular2 SDK

With JavaScript, it is possible to use the libraries from CDN, NPM, and Bower.

1. Include global dependencies for Angular2: 1<script src="node_modules/core-js/client/shim.min.js"></script>2<script src="node_modules/zone.js/dist/zone.js"></script>3<script src="node_modules/reflect-metadata/Reflect.js"></script>4<script src="node_modules/rxjs/bundles/Rx.js"></script>
2. Include Angular2 1<script src="node_modules/@angular/core/bundles/core.umd.js"></script>2<script src="node_modules/@angular/common/bundles/common.umd.js"></script>3<script src="node_modules/@angular/compiler/bundles/compiler.umd.js"></script>4<script src="node_modules/@angular/platform-browser/bundles/platform-browser.umd.js"></script>5<script src="node_modules/@angular/forms/bundles/forms.umd.js"></script>6<script src="node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js"></script>
3. Include the latest version of the PubNub JavaScript SDK: 1<script src="node_modules/pubnub/dist/web/pubnub.js"></script>
4. Include the PubNub Angular2 SDK: 1<script src="node_modules/pubnub-angular2/dist/pubnub-angular2.js"></script>

### Integrate PubNub Angular2 SDK into your app with TypeScript

Your HTML page needs to include the libraries described above, but you need to load Angular2 and the PubNub Angular2 SDK from NPM modules.

1. Include global dependencies for Angular2: 1<script src="node_modules/core-js/client/shim.min.js"></script>2<script src="node_modules/zone.js/dist/zone.js"></script>3<script src="node_modules/reflect-metadata/Reflect.js"></script>4<script src="node_modules/rxjs/bundles/Rx.js"></script>
2. Include the latest version of the PubNub JavaScript SDK: 1<script src="node_modules/pubnub/dist/web/pubnub.js"></script>
3. Include and load libraries from systemjs: 1<script src="node_modules/systemjs/dist/system.src.js"></script>2<script src="systemjs.config.js"></script>3<script>4 System.import('app').catch(function(err){5 console.error(err);6 });7</script>

Angular2 uses `systemjs.config.js`. Include the following libraries inside the map attribute:

* Rxjs
* Angular2
* PubNub Angular2 SDK

#### Your systemjs.config.js should look like this:

```javascript
map: {
    'rxjs': 'npm:rxjs',
    '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
    '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
    '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
    '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
    '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
    '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
    '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
    '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
    'pubnub-angular2': 'npm:pubnub-angular2/dist/pubnub-angular2.js'
}
```

#### Register the PubNub Angular2 SDK into Angular's list of providers

There are two ways to register the **PubNub Angular2 SDK** in your app's list of providers: Angular Modules, and Components.

An **Angular Module** lets you use the same instance of **PubNub** in all Angular Components declared in the module. Then, you do not need to register **PubNub** in any Angular Component hosted by the Angular Module.

##### Registering inside an Angular module using JavaScript

```javascript
'use strict';

(function (app) {
    app.appModule = ng.core.NgModule({
        imports: [ng.platformBrowser.BrowserModule],
        declarations: [app.appComponent],
        providers: [ PubNubAngular ],
        bootstrap: [app.appComponent]
    }).Class({
        constructor: function(){}
    });

    document.addEventListener('DOMContentLoaded', function(){
        ng.platformBrowserDynamic.platformBrowserDynamic().bootstrapModule(app.appModule);
    });
})(window.app || (window.app = {}));
```

##### Registering inside an Angular module using TypeScript

```javascript
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { PubNubAngular } from 'pubnub-angular2';
import { AppComponent } from './appComponent';
@NgModule({
    imports:[ BrowserModule ],
    declarations:[ AppComponent ],
    providers:[ PubNubAngular ],
    bootstrap:[ AppComponent ]
})
export class AppModule {
    constructor() {}
}
```

An **Angular Component** only lets to use the same instance of **PubNub** inside itself and its Angular Components children. For more information about this, refer to [Dependency Injection](https://angular.io/guide/dependency-injection) and [Hierarchical Dependency Injectors](https://angular.io/guide/hierarchical-dependency-injection)

##### Registering inside an Angular component using JavaScript

```javascript
(function (app) {
    app.appComponent = ng.core.Component({
        selector: 'appComponent',
        template: '<H1>PubNub Angular2 SDK Demo</H1>'
        providers: [ PubNubAngular ]
    }).Class({
        constructor: function () {}
    });
})(window.app || (window.app = {}));
```

##### Registering inside an Angular component using TypeScript

```javascript
import { Component } from '@angular/core';
import { PubNubAngular } from 'pubnub-angular2';
@Component({
    selector: 'appComponent',
    template: '<H1>PubNub Angular2 SDK Demo</H1>',
    providers: [PubNubAngular]
})
export class AppComponent {
    constructor() {}
}
```

#### How to inject PubNubAngular

Registering **PubNubAngular** within the provider list in an Angular Module or Component lets you inject a **PubNub** instance into an Angular Component according to the [Hierarchical Dependency](https://angular.io/guide/hierarchical-dependency-injection) then this will be a shared instance.

After injecting the **PubNub** instance in the Angular Component's constructor, initialize the service including the `PUB_KEY` and `SUB_KEY`. This process only has to be done once, since this instance is shared by all Angular Components within the same dependency scope.

##### Injecting an instance of PubNub using JavaScript

:::note
Always set the `UUID` to uniquely identify the user or device that connects to PubNub. This `UUID` should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the `UUID` can significantly impact your billing if your account uses the [Monthly Active Users (MAUs)](https://www.pubnub.com/pricing/) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
:::

```javascript
(function (app) {
    app.appComponent = ng.core.Component({
        selector: 'appComponent',
        template: '<H1>PubNub Angular2 SDK Demo</H1>'
    }).Class({
        constructor: [PubNubAngular, function(pubnub){
            pubnub.init({
                publishKey: 'YOUR PUB_KEY',
                subscribeKey: 'YOUR SUB_KEY'
            });
        }]
    });
})(window.app || (window.app = {}));
```

##### Injection an instance of PubNub using TypeScript

:::note
Always set the `UUID` to uniquely identify the user or device that connects to PubNub. This `UUID` should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the `UUID` can significantly impact your billing if your account uses the [Monthly Active Users (MAUs)](https://www.pubnub.com/pricing/) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
:::

```javascript
import { Component } from '@angular/core';
import { PubNubAngular } from 'pubnub-angular2';
@Component({
    selector: 'appComponent',
    template: '<H1>PubNub Angular2 SDK Demo</H1>'
})
export class AppComponent {
    constructor(pubnub: PubNubAngular) {
        pubnub.init({
            publishKey: 'YOUR PUB_KEY',
            subscribeKey: 'YOUR SUB_KEY'
        });
    }
}
```

### Differences in usage with native JavaScript SDK

To learn about **PubNub JavaScript** features, refer to the [PubNub JavaScript SDK documentation](https://www.pubnub.com/docs/sdks/javascript) All methods of this SDK are wrapped with **PubNubAngular**

Native **PubNub JavaScript SDK** provides instance creation using `Pubnub.init()`, which returns a new instance with given credentials. In **PubNub Angular2 SDK** instances are hidden inside the service and are accessible via instance getters. Methods of default instance are mapped directly to the **PubNub** service, such as `Pubnub.publish({...})`. In most use cases, you can use only the default PubNub instance, but if you need multiple instances with different credentials, you should use the `Pubnub.getInstance(instanceName)` getter. In this case, the publish method is `Pubnub.getInstance(instanceName).publish({})`.

#### How to use the native PubNub JavaScript SDK

##### Native PubNub JavaScript SDK

:::note
Always set the `UUID` to uniquely identify the user or device that connects to PubNub. This `UUID` should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the `UUID` can significantly impact your billing if your account uses the [Monthly Active Users (MAUs)](https://www.pubnub.com/pricing/) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
:::

```javascript
var defaultInstance = new PubNub({
    publishKey: 'YOUR PUB_KEY',
    subscribeKey: 'YOUR SUB_KEY'
});

var anotherInstance = new PubNub({
    publishKey: 'ANOTHER PUB_KEY',
    subscribeKey: 'ANOTHER SUB_KEY'
});

defaultInstance.publish(
    {
        message: {such: 'Hello!'},
        channel: 'my_channel'
    },
    function (status, response) {
        if (status.error) {
            console.log(status);
        } else {
            console.log("message Published w/ timetoken", response.timetoken);
        }
    }
);

anotherInstance.grant(
    {
        channels: ['my_channel'],
        authKeys: ['my_authkey'],
        read: true,
        write: false
    },
    function (status) {
        console.log(status);
    }
);
```

##### Native PubNub JavaScript SDK using TypeScript

:::note
Always set the `UUID` to uniquely identify the user or device that connects to PubNub. This `UUID` should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the `UUID` can significantly impact your billing if your account uses the [Monthly Active Users (MAUs)](https://www.pubnub.com/pricing/) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
:::

```javascript
declare var PubNub: any;

var defaultInstance = new PubNub({
    publishKey: 'YOUR PUB_KEY',
    subscribeKey: 'YOUR SUB_KEY'
});

var anotherInstance = new PubNub({
    publishKey: 'ANOTHER PUB_KEY',
    subscribeKey: 'ANOTHER SUB_KEY'
});

defaultInstance.publish(
    {
        message: {such: 'Hello!'},
        channel: 'my_channel'
    },
    (status, response) => {
        if (status.error) {
            console.log(status);
        } else {
            console.log('message Published w/ timetoken', response.timetoken);
        }
    }
);

anotherInstance.grant(
    {
        channels: ['my_channel'],
        authKeys: ['my_authkey'],
        read: true,
        write: false
    },
    (status) => {
        console.log(status);
    }
);
```

#### How to use PubNubAngular SDK

##### Using the PubNub Angular2 SDK with JavaScript

:::note
Always set the `UUID` to uniquely identify the user or device that connects to PubNub. This `UUID` should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the `UUID` can significantly impact your billing if your account uses the [Monthly Active Users (MAUs)](https://www.pubnub.com/pricing/) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
:::

```javascript
(function (app) {
    app.appComponent = ng.core.Component({
        selector: 'appComponent',
        template: '<H1>PubNub Angular2 SDK Demo</H1>'
    }).Class({
        constructor: [PubNubAngular, function(pubnub){
            pubnub.init({
                publishKey: 'YOUR PUB_KEY',
                subscribeKey: 'YOUR SUB_KEY'
            });

            pubnub.getInstance("another").init({
                publishKey: 'ANOTHER PUB_KEY',
                subscribeKey: 'ANOTHER SUB_KEY'
            });

            pubnub.publish(
               {
                    message: {
                        such: 'Hello!'
                    },
                    channel: 'my_channel'
                },
                function (status, response) {
                    if (status.error) {
                        console.log(status);
                    } else {
                        console.log('message Published w/ timetoken', response.timetoken);
                    }
                }
            );

            pubnub.getInstance('another').grant(
                {
                    channels: ['my_channel'],
                    authKeys: ['my_authkey'],
                    read: true,
                    write: false
                },
                function (status) {
                    console.log(status);
                }
            );
        }]
    });
})(window.app || (window.app = {}));
```

##### Using the PubNub Angular2 SDK with TypeScript

:::note
Always set the `UUID` to uniquely identify the user or device that connects to PubNub. This `UUID` should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the `UUID` can significantly impact your billing if your account uses the [Monthly Active Users (MAUs)](https://www.pubnub.com/pricing/) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
:::

```javascript
import { Component } from '@angular/core';
import { PubNubAngular } from 'pubnub-angular2';

@Component({
    selector: 'appComponent',
    template: '<H1>PubNub Angular2 SDK Demo</H1>'
})

export class AppComponent {
    constructor(pubnub: PubNubAngular) {
        pubnub.init({
            publishKey: 'YOUR PUB_KEY',
            subscribeKey: 'YOUR SUB_KEY'
        });

        pubnub.getInstance('another').init({
            publishKey: 'ANOTHER PUB_KEY',
            subscribeKey: 'ANOTHER SUB_KEY'
        });

        pubnub.publish(
            {
                message: {such: 'Hello!'},
                channel: 'my_channel'
            },
            (status, response) => {
                if (status.error) {
                    console.log(status);
                } else {
                    console.log('message Published w/ timetoken', response.timetoken);
                }
            }
        );

        pubnub.getInstance("another").grant(
            {
                channels: ['my_channel'],
                authKeys: ['my_authkey'],
                read: true,
                write: false
            }, (status) => {
                console.log(status);
            }
        );
    }
}
```

That's it, you're ready to start using the **PubNub Angular SDK**

### Description

This function is used for initializing the PubNub Client API context. This function must be called before attempting to utilize any API functionality in order to establish account level credentials such as `publishKey` and `subscribeKey`.

### Method(s)

To `Initialize` PubNub you can use the following method(s) in the Angular2 SDK:

```javascript
PubNub( {String subscribeKey, String publishKey, String cipherKey, String authKey, Boolean logVerbosity, String uuid, Boolean ssl, String origin, Number presenceTimeout, Number heartbeatInterval, Boolean restore, Boolean keepAlive, Object keepAliveSettings, Boolean suppressLeaveEvents, Number requestMessageCountThreshold, Boolean listenToBrowserNetworkEvents} )
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| subscribeKey | String | Yes |  | Specifies the `subscribeKey` to be used for subscribing to a channel. This key can be specified at initialization or along with a `subscribe()`. |
| publishKey | String | Optional |  | Specifies the `publishKey` to be used for publishing messages to a channel. This key can be specified at initialization or along with a `publish()`. |
| cipherKey | String | Optional |  | If passed, will encrypt the payloads. |
| authKey | String | Optional |  | If Access Manager enabled, this key will be used on all requests. |
| logVerbosity | Boolean | Optional | `false` | log HTTP information. |
| uuid | String | Yes |  | `UUID` to use. You should set a unique `UUID` to identify the user or the device that connects to PubNub. If you don't set the `UUID`, you won't be able to connect to PubNub. |
| ssl | Boolean | Optional | `true` | If set to `true`, requests will be made over HTTPS. |
| origin | String | Optional | `ps.pndsn.com` | If a custom domain is required, SDK accepts it here. To request a custom domain, contact support and follow the [request process](https://www.pubnub.com/docs/general/setup/data-security#request-process). |
| presenceTimeout | Number | Optional | `300` | How long the server will consider the client alive for presence. The value is in seconds. |
| heartbeatInterval | Number | Optional | `Not Set` | How often the client will announce itself to server. The value is in seconds. Due to server constraints, don't set the value below `3`. |
| restore | Boolean | Optional | `false` | `true` to allow catch up on the front-end applications. |
| keepAlive | Boolean | Optional | `false` | If set to `true`, SDK will use the same TCP connection for each HTTP request, instead of opening a new one for each new request. |
| keepAliveSettings | Object | Optional | `keepAliveMsecs: 1000 freeSocketKeepAliveTimeout: 15000 timeout: 30000 maxSockets: Infinity maxFreeSockets: 256` | Set a custom parameters for setting your connection `keepAlive` if this is set to `true`.`keepAliveMsecs: (Number)` how often to send TCP KeepAlive packets over sockets.`freeSocketKeepAliveTimeout: (Number)` sets the free socket to timeout after freeSocketKeepAliveTimeout milliseconds of inactivity on the free socket.`timeout: (Number)` sets the working socket to timeout after timeout milliseconds of inactivity on the working socket.`maxSockets: (Number)` maximum number of sockets to allow per host.`maxFreeSockets: (Number)` maximum number of sockets to leave open in a free state. |
| suppressLeaveEvents | Boolean | Optional | `false` | When `true` the SDK doesn't send out the leave requests. |
| requestMessageCountThreshold | Number | Optional | `100` | `PNRequestMessageCountExceededCategory` is thrown when the number of messages into the payload is above of `requestMessageCountThreshold`. |
| listenToBrowserNetworkEvents | Boolean | Optional | `false` | If the browser fails to detect the network changes from WiFi to LAN and vice versa or you get reconnection issues, set the flag to `false`. This allows the SDK reconnection logic to take over. |

### Sample code

#### Initialize the PubNub client API

:::note
Always set the `UUID` to uniquely identify the user or device that connects to PubNub. This `UUID` should be persisted, and should remain unchanged for the lifetime of the user or the device. If you don't set the `UUID`, you won't be able to connect to PubNub.
:::

```javascript
pubnub.init({
    subscribeKey: "YOUR SUB_KEY",
    publishKey: "YOUR PUB_KEY",
    ssl: true
});
```

### Returns

It returns the PubNub instance for invoking PubNub APIs like `publish()`, `subscribe()`, `history()`, `hereNow()`, etc.

### Other examples

#### Initialize the client

:::note
Always set the `UUID` to uniquely identify the user or device that connects to PubNub. This `UUID` should be persisted, and should remain unchanged for the lifetime of the user or the device. If you don't set the `UUID`, you won't be able to connect to PubNub.
:::

```javascript
pubnub.init({
    subscribeKey: 'YOUR SUB_KEY',
    publishKey: 'YOUR PUB_KEY',
    ssl: true
});
```

#### Initialization for a Read-Only client

In the case where a client will only read messages and never publish to a channel, you can simply omit the `publishKey` when initializing the client:

:::note
Always set the `UUID` to uniquely identify the user or device that connects to PubNub. This `UUID` should be persisted, and should remain unchanged for the lifetime of the user or the device. If you don't set the `UUID`, you won't be able to connect to PubNub.
:::

```javascript
pubnub.init({
    subscribeKey: "YOUR SUB_KEY"
});
```

#### Use a custom UUID

Set a custom `UUID` to identify your users.

:::note
Always set the `UUID` to uniquely identify the user or device that connects to PubNub. This `UUID` should be persisted, and should remain unchanged for the lifetime of the user or the device. If you don't set the `UUID`, you won't be able to connect to PubNub.
:::

```javascript
pubnub.init({
    publishKey: 'myPublishKey',
    subscribeKey: 'mySubscribeKey',
    uuid: 'myUniqueUUID'
});
```

#### Initializing with SSL enabled

This examples demonstrates how to enable PubNub Transport Layer Encryption with `SSL`. Just initialize the client with `ssl` set to `true`. The hard work is done, now the PubNub API takes care of the rest. Just subscribe and publish as usual and you are good to go.

:::note
Always set the `UUID` to uniquely identify the user or device that connects to PubNub. This `UUID` should be persisted, and should remain unchanged for the lifetime of the user or the device. If you don't set the `UUID`, you won't be able to connect to PubNub.
:::

```javascript
pubnub.init({
    subscribeKey: "YOUR SUB_KEY",
    publishKey: "YOUR PUB_KEY",
    ssl: true
});
```

#### Initializing with Access Manager

:::note Requires Access Manager add-on
This method requires that the *Access Manager* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

:::note
Anyone with the `secretKey` can grant and revoke permissions to your app. Never let your `secretKey` be discovered, and to only exchange it / deliver it securely. Only use the `secretKey` on secure environments such as `Node.js` application or other server-side platforms.
When you init with `secretKey`, you get root permissions for the Access Manager. With this feature you don't have to grant access to your servers to access channel data. The servers get all access on all channels.
:::

For applications that will administer Access Manager permissions, the API is initialized with the `secretKey` as in the following example:

:::note
Always set the `UUID` to uniquely identify the user or device that connects to PubNub. This `UUID` should be persisted, and should remain unchanged for the lifetime of the user or the device. If you don't set the `UUID`, you won't be able to connect to PubNub.
:::

```javascript
pubnub.init({
    subscribeKey: 'YOUR SUB_KEY',
    publishKey: 'YOUR PUB_KEY',
    secretKey: 'YOUR SECRET_KEY'
});
```

Now that the pubnub object is instantiated the client will be able to access the Access Manager functions. The pubnub object will use the `secretKey` to sign all Access Manager messages to the PubNub Network.

## UUID

These functions are used to set/get a user ID on the fly.

### Method(s)

To set/get `UUID` you can use the following method(s) in Angular2 SDK:

```javascript
pubnub.setUUID(string)
```

| Parameter | Description |
| --- | --- |
| `uuid` *Type: String | `UUID` to set. |

```javascript
pubnub.getUUID()
```

This method doesn't take any arguments.

### Sample code

#### Set UUID

:::note
Always set the `UUID` to uniquely identify the user or device that connects to PubNub. This `UUID` should be persisted, and should remain unchanged for the lifetime of the user or the device. If you don't set the `UUID`, you won't be able to connect to PubNub.
:::

```javascript
pubnub.setUUID('myUniqueUUID');
```

#### Get UUID

```javascript
var uuid = pubnub.getUUID();
```

## Authentication key

This function provides the capability to reset a user's auth Key.

Typically auth Key is specified during initialization for Access Manager enabled applications. In the event that auth Key has expired or a new auth Key is issued to the client from a Security Authority, the new auth Key can be sent using `setAuthKey()`.

### Property

To `Set Authentication Key` you can use the following method(s) in the Angular2 SDK:

```javascript
pubnub.setAuthKey(string)
```

| Parameter | Description |
| --- | --- |
| `key` *Type: String | `Auth key` to set. |

### Sample code

```javascript
pubnub.setAuthKey('my_authkey');
```

### Returns

None.

## Filter expression

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

Stream filtering allows a subscriber to apply a filter to only receive messages that satisfy the conditions of the filter. The message filter is set by the subscribing client(s) but it is applied on the server side thus preventing unwanted messages (those that do not meet the conditions of the filter) from reaching the subscriber.

To set or get message filters, you can use the following method.

### Method(s)

```javascript
pubnub.setFilterExpression(String filterExpression)
```

| Parameter | Description |
| --- | --- |
| `filterExpression` *Type: String | PSV2 feature to `subscribe` with a custom filter expression. |

```javascript
pubnub.getFilterExpression()
```

This method doesn't take any arguments.

### Sample code

#### Set filter expression

```javascript
pubnub.setFilterExpression("such=wow");
```

#### Get filter expression

```javascript
pubnub.getFilterExpression();
```

## 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.
