Bitcore-p2p: Peer.connect does not work I'm trying to run a simple script to connect to a Bitcoin peer, like this one:

var bitcore = require('bitcore-lib')
var p2p = require('bitcore-p2p')
var Peer = p2p.Peer;

var peer = new Peer({host: 'localhost', port: 18333, network: Networks.testnet})
peer.on('connect', function () { console.log('connect'); })
peer.on('ready', function(){  console.log('ready'); });
peer.on('disconnect', function() {  console.log('connection closed'); });
peer.connect()


However, the connection seems to never be established.
I only get the 'connect' and the 'connection closed' output, but not 'connected'. 
The port I set is the one in the Bitcore config file.

Can someone please help me figure out what is the problem?
I'm not sure what exactly you are trying to do with: 

peer.on('connected', function(){  console.log('connected'); });

You can just do on ready instead.

peer.on('ready', function(){  console.log('connected'); });

Example connecting to a peer and receiving notifications

var bitcore = require('bitcore-lib');
var Peer = require('bitcore-p2p').Peer;

var peer = new Peer({host: "101.201.31.79"});
//IP of one of the btc.com's miners

peer.on('ready', function(){
    console.log("Connected "+peer.version, peer.subversion, peer.bestHeight);
});
peer.on('disconnect', function(){
    console.log("disconnected");
});
//loop through peer notifications
peer.on('inv', function(message){
    var nodeMsg = message.inventory;
    var nodeMsgLen = nodeMsg.length;
    for (var i = 0; i &lt; nodeMsgLen; i++){
        console.log(nodeMsg[i].hash);
    };
});
//connect
peer.connect();