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?
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 runserver/test.js
it seems to work fine