How to listen permanently to events in a smart contract from node.js Application?

Viewed 4696

I have a node js App which has the following code:

contract.getPastEvents('RequestCreated', function (error, event) { console.log(event); })
        .then(function (events) {
            console.log(events); 
        })

Once I run the node, I get an empty array.

My expectation is to get the value of the variable requestCount once the event in the smart contract is emited

    function createRequest(string memory _fileHash) public {
        requestCount++;
        fileHash[requestCount] = _fileHash;
        emit RequestCreated(requestCount);
    }

My question is how to listen to events occurring in the smart contract from a node js App?

I am using Web3 Version > 1, so the watch function is not the right one for me.

1 Answers
Related