title: Connecting to a telnet server in NodeJS
body: <p>There is a particular equipment here that can <strong>only</strong> be controlled via telnet, which I have been doing (through PuTTy or Terminal) for a while now.</p>
  
  <p>In NodeJS, I created a web interface that would make it easier to control the equipment. I did this by running different bash scripts for different commands sent through telnet. This is working fine, but it felt too unorganized, and not to mention the clutter of shell scripts for each command. I'm looking for a better way of doing this.</p>
  
  <p>I thought of connecting to the telnet server directly from NodeJS. I have tried different packages (i.e. net, telnet-client, telnet-stream, another-telnet-client, etc) but it's either those aren't the tools I need or I'm just not implementing it correctly.</p>
  
  <p>Here's a sample code I'm testing using the telnet-client package (others are just variations of this):</p>
  
  <pre><code>const telnet = require('telnet-client');
  const server = new telnet();
  
  // display server response
  server.on("data", function(data){
      console.log(''+data);
  });
  
  // login when connected
  server.on("connect", function(){
      server.write("login &lt;user&gt; &lt;pass&gt;");
  });
  
  // connect to server
  server.connect({
      host: "172.16.0.1",
      port: 9600
  });
  </code></pre>
  
  <p>When done manually, after the "login" request, I should see a "login successful" message but I'm not getting anything back.</p>
  
  <p>Is this code incorrect? I'm not familiar with telnet and would really appreciate any help.</p>