ステップ1 nodejs httpサーバを作成します。
- ロードモジュールはnodejsが必要です
- サーバーを作成し、クライアントをリッスン
- そして、要求に対する応答を受信
2 nodejs httpサーバのコードを作成します。
1.次のコードを記入し、server.jsという名前のファイルを作成します。
// 1. load http module
var http = require("http")
// 2. create http server
const server = http.createServer(function(request,response){
// send http head
// http status: 200:OK
// content type: text/plain
response.writeHead(200,{'Content-Type': 'text/plain'});
// send response data
response.end('Hello World\n')
})
server.listen(8080)
2.新しいサーバーのhttpを実行します。 node server.js
3. [http://127.0.0.1:8080/にアクセスするためのブラウザ、あなたは「Hello World」のページを参照してくださいと言っています。
ます。https://www.jianshu.com/p/8bbdd529e1e4で再現