Expressworks Hello World

I have been trying to get this to work, and I even checked the c9 docs, as well as the forum for others with the same issue (Setting to 8080, and/or setting process.env.IP still doesn’t work). Sure I could consider this done since I know it works outside of c9 perfectly fine (as well as in c9 in certain circumstances), but I believe it would be good to know what is stopping this with c9.

On this exercise, my code works perfectly fine with the expressworks run , but as soon as I use expressworks verify it sets the port, then fails to connect, as it tries to connect to the next port up (+1). Even when adding 1 to the process.env.PORT, it refuses to match up as it is then one less (-1).

My Code:
var express = require(‘express’);
var app = express();
var port = process.argv[2];

app.get('/home', (req, res) => {
  res.end('Hello World!');
console.log('Server listening on port ' + port);

$ expressworks run Hello.js
Server listening on port 3547
Hello World!

$ expressworks verify Hello.js
Server listening on port 27476
✗ Error connecting to http://localhost:27477/home: connect ECONNREFUSED

I’ve setup a c9 Run Configuration, and it’s obvious Express works (there weren’t any issues with Node or Mongo), but for whatever reason Expressworks fails. Any suggestions? Is there a way to force the port, or make expressworks ignore the need for the port being set with the command? Thanks in advance!

Do you close the session before running verify?

It may be seeing an open connection on that port and adding one to avoid collisions.

Indeed. Exact same terminal, and even tried running verify concurrently, only getting the exact same output every time. :frowning:

Well, you gave me an idea.

I went ahead and reloaded the VM, started by running verify first, and it ran without a hitch. For the future, I need to remember in that c9 can be flaky like that. Thanks!

If you can, I suggest you develop Node apps locally. You will do this if you get an actual job, please its a lot nicer to have your own customized editors and workflow.

1 Like

Thanks for the suggestion!

This is actually what I ended up moving back to. Even since I started the Back-End cert I thought that c9 was required, but once I found out it wasn’t I went right back to my own custom environments. It would be great if there was a footnote mentioning this somewhere when c9 is introduced, because it is quite the move from a personal IDE environment setup to c9, and then trying to iron out the nuances of c9 that you are not use to dealing with; especially fighting nvm.

Realistically I am surprised there isn’t a sub-section before the Node and after Git section, discussing the creation of your own environment. If needed, users could sync their environments to their GitHub for anyone to offer help, as well as check code/environments. If there is anything that I strongly believe full stack devs should learn to create for themselves, it is their own environment to make development more personalized for themselves. Everyone has their preferences, but at the very least should learn how to use boilerplates.

In the future, users will be suggested to use Gomix not c9. I tried it out today, it is super easy and fun… no worrying about servers, deploying to heroku - everything automatically becomes live, and click to export to github. Its especially nice for smaller api projects.

1 Like