0

I wrote the following code and ran it successfully on my local machine:

var express = require('express');
var app = express();

app.get('/', function(req,res) {
    res.send("OK");
});

app.listen(process.env.PORT, function() {
    console.log("listening on port " + process.env.PORT);
});

When I tried to run it on Cloud9 virtual machine, I encountered the following error:

SyntaxError: Unexpected token ILLEGAL
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.runMain [as _onTimeout] (module.js:441:10)
    at Timer.listOnTimeout (timers.js:92:15)

I looked at these posts: No visible cause for "Unexpected token ILLEGAL", How to display hidden characters in PhpStorm, especially line seperators.

This error means that there is probably an invisible character in the code. I installed "Zero Width Characters locator" plugin in my WebStorm, copied the code from Cloud9 and got no sign for illegal character.

What can be the problem?

Community
  • 1
  • 1
CrazySynthax
  • 13,662
  • 34
  • 99
  • 183

1 Answers1

1

Not certain if this is the issue or not, but...

Your command /home/ubuntu//.nvm/versions/node/v4.6.1/bin/node ./server/test.js appears to be the issue. If you simply run server/test.js it seems to work fine

Paul Stoner
  • 1,359
  • 21
  • 44
  • you're right. Now the code compiles. Now, how can I access it from a client computer? – CrazySynthax Dec 28 '16 at 20:58
  • I get the message: "Your code is running at https://*****1986.c9users.io." Now, I'm trying to access https://*****1986.c9users.io:3000 in the browser, and I don't get anything. – CrazySynthax Dec 28 '16 at 20:59
  • 1
    ok that is a new one for me. I don't use cloud9 hardly ever. That may be a new/different question. I'll keep looking though – Paul Stoner Dec 28 '16 at 21:03