Javascript HTTP模块加载错误Node.js

Javascript HTTP模块加载错误Node.js,javascript,node.js,Javascript,Node.js,我是Node.js的新手,在Windows 7上安装了Node.js(版本4.2.1)。 如果我写: var http = require("http"); 它说undefined,为什么会触发此错误?您需要安装额外的模块,如http,在项目的根文件夹中运行此命令: npm install http 您是否安装了http模块?如果您在REPL中执行此操作,它将返回undefined,因为这是赋值的返回值。如果然后键入http,它将显示其内容。我只需安装node.js并开始使用它。您能告诉我如

我是Node.js的新手,在Windows 7上安装了Node.js(版本4.2.1)。 如果我写:

var http = require("http");

它说
undefined
,为什么会触发此错误?

您需要安装额外的模块,如
http
,在项目的根文件夹中运行此命令:

npm install http

您是否安装了http模块?如果您在REPL中执行此操作,它将返回undefined,因为这是赋值的返回值。如果然后键入http,它将显示其内容。我只需安装node.js并开始使用它。您能告诉我如何在Windows7中安装http模块吗?问题解决了,我创建了一个文件,编写了上面的代码,如server.js,并在浏览器中运行代码。它工作正常,没有错误。谢谢你的帮助。
var http = require("http");
http.createServer(function (request, response) {

    // Send the HTTP header 
    // HTTP Status: 200 : OK
    // Content Type: text/plain
    response.writeHead(200, {'Content-Type': 'text/plain'});

    // Send the response body as "Hello World"
    response.end('Hello World\n');
}).listen(8081);

// Console will print the message
console.log('Server running at http://192.168.168.259:8081/');