Reputation: 1450
I believe I've gone from v0.10.31 to v.0.10.34 and since then, my node.js app is having problems.
/** Variables */
var app = require('http').createServer(handler),
io = require('socket.io').listen(app),
url = require('url');
/** Listen on port # */
app.listen( 60003 );
/**
* Parse server messages
* Redirect to home page if accessed directly
*/
function handler( request, response ) {
var requestURL = url.parse(request.url, true);
/** ... */
response.writeHead(302, {
'Location': 'http://www.google.com'
});
response.end();
}
cat ./nohup.out
./node.js: line 2: syntax error near unexpected token
(' ./node.js: line 2:
var app = require('http').createServer(handler),'
Upvotes: 0
Views: 207
Reputation: 106736
The error you're seeing is due to the way you're trying to execute your script. node ./node.js
works because you're explicitly loading the script via node.
However nohup ./node.js
does not work because the shell is expecting the file to be a shell script. If you want to execute your script in this way, you'll need to add the appropriate hash bang line to tell the shell what program to use to interpret the file. For example: #!/usr/bin/env node
Upvotes: 2