相关疑难解决方法(0)

我在node.js中的http.createserver不起作用?

大家好我刚刚开始学习node.js并在互联网上搜索很多东西,然后尝试在node.js中编码我使用这两个代码向我显示相同的结果,但最后一个是在我的浏览器上显示错误喜欢"无法找到页面"的东西.所以请向我解释原因?

// JScript source code
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
Run Code Online (Sandbox Code Playgroud)

这是有效的

// Include http module.
var http = require("http");

// Create the server. Function passed as parameter is called on every request made.
// request variable holds all request parameters
// response variable allows you to do anything with response sent to the client.
http.createServer(function (request, response) {
   // Attach listener on end event. …
Run Code Online (Sandbox Code Playgroud)

javascript node.js

12
推荐指数
2
解决办法
2万
查看次数

标签 统计

javascript ×1

node.js ×1