【发布时间】:2015-02-12 04:17:11
【问题描述】:
我已经在 Ubuntu (14.04) 上安装了 NodeJS,我正在尝试让我的第一个代码工作:
var http = require("http");
http.createServer(function(request,response){
response.writeHead(200, {"Content-Type": "text/html"});
response.write("<html>");
response.write("<head><title>Node.JS</title></head>");
respons.write("<body>Hello web</body>");
respons.write("</html>");
response.end();
}),
listen(9999);
我收到此错误:
/home/privateuser/nodejsweb/helloweb.js:11
listen(9999);
^
ReferenceError: listen is not defined
at Object.<anonymous> (/home/privateuser/nodejsweb/helloweb.js:11:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
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:929:3
在安装 NodeJS 期间,我在安装可选“某物”期间遇到错误: 可选:安装构建工具 要从 npm 编译和安装本机插件,您可能还需要安装构建工具: apt-get install -y build-essential
得到错误:=> E: Kon het vergrendelingsbestand '/var/lib/dpkg/lock' niet openen - open (13: Toegang geweigerd) E: Kan de beheersmap (/var/lib/dpkg/) niet vergrendelen。你对你有什么要求吗?
当我将此命令与 sudo 一起使用时,它告诉我上一个版本已经安装?
然后我尝试了: 自动运行节点 helloweb.js 进入自动适配模式:node helloweb.js 退出命令以退出自动适应模式。
但还是给出了listen的参考错误?
请帮忙,这是我使用 Ubuntu 的第二天,也是我的第一个 NodeJS 示例,我现在已经卡住了:(
提前感谢您的帮助!
【问题讨论】: