title: Nodejs Express API with NATS?
body: <p>I am trying to build a REST API for my frontend app using nodejs + express + nats.
  I have a nats-server running in my terminal.</p>
  <p>This is my test code:</p>
  <pre><code>var express = require(&quot;express&quot;);
  var app = express();
  const NATS = require('nats');
  const nc = NATS.connect();
  nc.on('connect', () =&gt; {
      console.log('connected');
  })
  
  nc.publish('foo', 'Hello World!');
  
  app.get('/', (req,res) =&gt; {
      nc.subscribe('foo', function (msg) {
          res.send(msg)
      });
  });
  
  app.listen(3000, () =&gt; {
   console.log(&quot;Server running on port 3000&quot;);
  });
  </code></pre>
  <p>After running test code, localhost:3000 cannot be reached.</p>
  <p>I found a similar project on github: <a href="https://github.com/georgehaidar/poc-express-nats/blob/master/api.js" rel="nofollow noreferrer">https://github.com/georgehaidar/poc-express-nats/blob/master/api.js</a>.</p>
  <p>I cant seem to find my error.</p>
  <p>Can anyone plz help me figure out what im doin wrong?</p>
  <p>Thank you in advance.</p>