Node.Webサーバをjsにオフセット
7433 ワード
Node.js
Google ChromeのJsva Scriptエンジン(V 8 Engine)に基づいて構築されたサーバ側プラットフォームです.
Node.jsは、Webサーバではなくコードを実行する方法です.
特長
よくどこに使いますか。
Webサーバのオフセット
// Node.js에 내장된 라이브러리
const http = require("http");
http.createServer(function (req, res){
// 요청에 응답 헤더를 보내는 ‘http’ 모듈의 내장 속성
res.writeHead(200);
// 응답 끝내기. 함수의 return과 비슷하다.
res.end("Hello World!");
}).listen(3000, function() {
console.log("Server on : 3000 port");
})
createServer()
は、第1のパラメータとしてコールバック関数を受け入れる.req
はリクエスト対象(リクエスト)である.res
は応答対象(response)である.listen()
は、特定のポートを開く関数です.アドレスウィンドウに
localhost:3000
と入力すると確認できます.const http = require("http");
http.createServer((req, res) => {
let url = req.url;
let method = req.method;
let headers = req.headers;
console.log(url);
console.log(method);
console.log(headers);
res.writeHead(200);
// 한글은 인코딩,,이 필요함
res.end("hello");
}).listen(3000, () => {
console.log("server on : 3000 port");
});
res.end
の文字列がハングルであれば、別途符号化する必要があります.server on : 3000 port
/<- url
GET <- method
{
host: 'localhost:3000',
connection: 'keep-alive',
'sec-ch-ua': '"Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"',
'sec-ch-ua-mobile': '?0',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
'sec-ch-ua-platform': '"macOS"',
accept: 'image/avif,image/webp,image/apng,image/svg+xml,image/,/*;q=0.8',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'no-cors',
'sec-fetch-dest': 'image',
referer: ' http://localhost:3000/' ,
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7'
} <- header
Reference
この問題について(Node.Webサーバをjsにオフセット), 我々は、より多くの情報をここで見つけました https://velog.io/@pongdang/Node.js로-웹-서버-띄우기テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol