2017-08-23 7 views
0

Im self-educating Node.js.私は2つのシンプルなHTMLファイル(summer.htmlとwinter.html)を作成し、ノードをnode.jsにnodeしました。私は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 

を持って、ローカルホスト上で結果を表示することができた:5354 /しかし、この1つのdoesntの仕事を。私は何を間違えたのですか?

JS

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); 
+0

あなたのserver.js(またはmain.js、メインバックエンドjsファイル)のルーティングを処理するか、htmlファイルをindex.htmlに関連付ける必要があります –

+1

あなたはリスニングポートです5343、ブラウザでは5354を使用しています。 – alexmac

+0

通常、単純なポートが使用されます(3000など)。 – alexmac

答えて

2

ヒットこのURLを はlocalhost:5343/summer.html

あなたは5343 PORTに耳を傾け、ので。しかし、5354ポートヒット

関連する問題