Node.js 要分析不起作用的查询字符串

Node.js 要分析不起作用的查询字符串,node.js,Node.js,Im self-education Node.js。我创建了两个简单的HTML文件(summer.HTML和winter.HTML),并在node.JS上添加了JS。我选择了localhost:5354/summer.html(和winter.html)。没有显示任何内容,我收到一条错误消息 This site can’t be reached The connection was reset. Try: Checking the connection Checking the proxy a

Im self-education Node.js。我创建了两个简单的HTML文件(summer.HTML和winter.HTML),并在node.JS上添加了JS。我选择了localhost:5354/summer.html(和winter.html)。没有显示任何内容,我收到一条错误消息

This site can’t be reached

The connection was reset.
Try:
Checking the connection
Checking the proxy and the firewall
Running Windows Network Diagnostics
ERR_CONNECTION_RESET
我已经测试了其他课程,并且能够在localhost:5354/上显示结果,但这一个不起作用。我做错了什么

JS

点击这个网址 localhost:5343/summer.html

因为,你在5343端口收听。但是你点击了5354端口

点击了这个URL localhost:5343/summer.html


因为,你在5343端口收听。但是你点击了5354端口

你需要在server.js(或main.js,主要后端js文件)中处理路由,或者将html文件放置在与索引相关的位置。HTMLY你正在监听端口5343,但在浏览器中使用5354。通常使用的是一个简单的端口,例如3000。我的错,实际上是5354而不是5343!真是个笨蛋!我再次检查了netstat并显示了5354。非常感谢你!您需要在server.js(或main.js,主要后端js文件)中处理路由,或将html文件放置在与索引相关的位置。HTMLY您正在侦听端口5343,但在浏览器中使用5354。通常使用一个简单的端口,例如3000。我的错,它实际上是5354而不是5343!真是个笨蛋!我再次检查了netstat并显示了5354。非常感谢你!
var http = require('http');
var url = require('url');
var fs = require('fs');

http.createServer(function (req, res) {
    var q = url.parse(req.url, true);
    var filename = "." + q.pathname;
    fs.readFile(filename, function(err, data) {
        if (err) {
            res.writeHead(404, {'Content-Type': 'text/html'});
            return res.end("404 Not Found");
        }
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.write(data);
        return res.end();
    });
}).listen(5343);