我试图在Ubuntu 14.04运行一个简单的脚本的NodeJS的大门,其内容如下:无效的ELF头了运行简单的脚本的NodeJS
http = require('http');
http.createServer(function(req, res){
res.writeHead(200, {'Content-Type': 'text/plain' });
res.end('Hello World \n');
}).listen(80, '127.0.0.1');
我已经通过了安装的NodeJS说明found here。下面是我从该链接遵循的摘录:
Option 2: Install Node.js with Ubuntu Package Manager
To install Node.js, type the following command in your terminal:
sudo apt-get install nodejs
Then install the Node package manager, npm:
sudo apt-get install npm
Create a symbolic link for node, as many Node.js tools use this name to execute.
sudo ln -s /usr/bin/nodejs /usr/bin/node
我这样做,证明这两个软件包安装:
但我不能用我的.node档案,而不要抱怨与此错误:
[email protected]:/var/www/html/nodetest$ node test.node
module.js:356
Module._extensions[extension](this, filename);
^
Error: /var/www/html/nodetest/test.node: invalid ELF header
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:945:3
我已经卸载和重新安装节点以及NPM,但它仍然无法正常工作...我运行Ubuntu 14.04 LTS 64位。
更多信息:
我决定从源代码和https://github.com/nodejs/node.git克隆master
,建设它,然后运行相同的脚本之后打造,这是我得到的错误:
[email protected]:/var/www/html/nodetest$ ~/node/node test.node
module.js:600
return process.dlopen(module, path._makeLong(filename));
^
Error: /var/www/html/nodetest/test.node: invalid ELF header
at Object.Module._extensions..node (module.js:600:18)
at Module.load (module.js:490:32)
at tryModuleLoad (module.js:449:12)
at Function.Module._load (module.js:441:3)
at Module.runMain (module.js:607:10)
at run (bootstrap_node.js:414:7)
at startup (bootstrap_node.js:139:9)
at bootstrap_node.js:529:3
这是相同的错误,显然,与不同的堆栈跟踪。
什么给?
控制台输出引述看起来比图片要好得多,因为仅仅反差太大介绍(和你没有虚拟机下运行它W/O副本 - 我可以看到可用的膏状物)。 – agg3l
只是一个疯狂的猜测 - 不能是关于你的脚本错误的文件编码node.js无法解释?像UTF8 + BOM或UTF16 ... – agg3l
我只是在我的Pi上运行相同的步骤运行Raspbian Jessie,同样的事情发生。我还没有检查文件的编码,但是nodejs需要什么编码? – Brandon