我相信我已经从 v0.10.31 升级到 v.0.10.34,从那时起,我的 Node.js 应用程序出现了问题。
/** 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();
}
猫./nohup.out
./node.js: line 2: syntax error near unexpected token
(' ./node.js: line 2:
var app = require('http').createServer(handler),'
最佳答案
您看到的错误是由于您尝试执行脚本的方式造成的。 node ./node.js
可以工作,因为您是通过 Node 显式加载脚本。
但是 nohup ./node.js
不起作用,因为 shell 期望该文件是 shell 脚本。如果您想以这种方式执行脚本,则需要添加适当的 hash bang 行来告诉 shell 使用哪个程序来解释该文件。例如:#!/usr/bin/env Node
关于javascript - Node.js 版本已更改,脚本不再工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27610533/