TelNet In A nodejs Workspace


#1

Hello.

I’m trying to connect to a TCP socket server with Telnet.

The command I’m trying to use is:

$ telnet localhost 5432

It is giving me this error:

bash: localhost: command not found

What’s up?


#2

Try using telnet 127.0.0.1 5432


#3

Same error.

I thought I needed to add a telnet client for nodejs so I tried

npm install -g telnet-client

But that didn’t work either.


#4

Here’s my code:

‘use strict’;
const
fs = require(‘fs’),
net = require(‘net’),
filename = process.argv[2],
server = net.createServer(function(connection) {
//reporting
console.log(‘Subscriber connected.’);
connection.write(“Now watching '” + filename + “’ for changes…\n”);
//watcher setup
let watcher = fs.watch(filename, function(){
connection.write(“File '” + filename + "’ changed: " + Date.now() + “\n”);
});
// cleanup
connection.on(‘close’, function() {
console.log(‘Subscriber disconnected.’);
watcher.close();
});
});
if (!filename) {
throw Error(‘No target filename was specified.’);
}
server.listen(5432, function(){
console.log(‘Listening for subscribers…’);
});

The command I then run is:
$ node --harmony net-watcher.js target.txt

I then open a second terminal and try this:
$ telnet localhost 5432