> For the complete documentation index, see [llms.txt](https://soufatn.gitbook.io/rxjs-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://soufatn.gitbook.io/rxjs-book/summary/rxjs_bindings/node/event_handlers/to_event_emitter.md).

# toEventEmitter

## `Rx.Node.toEventEmitter(observable, eventName)` <a href="#rxnodetoeventemitterobservable-eventname" id="rxnodetoeventemitterobservable-eventname"></a>

[#](/rxjs-book/summary/rxjs_bindings/node/event_handlers/to_event_emitter.md#rxnodetoeventemitterobservable-eventname) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/rx.node.js#L66-L84)

Converts the given observable sequence to an event emitter with the given event name. The errors are handled on the 'error' event and completion on the 'end' event.

### Arguments

1. `observable` *(Obsesrvable)*: The observable sequence to convert to an EventEmitter.
2. `eventName` *(String)*: The event name to subscribe.

### Returns

*(EventEmitter)*: An EventEmitter which emits the given eventName for each onNext call in addition to 'error' and 'end' events.

### Example

```javascript
var Rx = require('Rx');

var source = Rx.Observable.return(42);

var emitter = Rx.Node.toEventEmitter(source, 'data');

emitter.on('data', function (data) {
    console.log('Data: ' + data); 
});

emitter.on('end', function () {
    console.log('End');
});

// Ensure to call publish to fire events from the observable
emitter.publish();

// => Data: 42
// => End
```
