http.createServer

http.createServerで、サーバソケットを作成する。

HTTP | Node.js v16.13.2 Documentation

リクエストやレスポンスを操作するrequestListenerを渡す以外に、optionsも渡せるみたいだが、これは難しそうなので、戻り値の中身を見てみる。

console.logでserverをそのまま出力。

こんな感じでいっぱい出力される
こんな感じでいっぱい出力される

サーバ起動して、アクセスするとこんな感じでいっぱい出力された。

$ vi http.js
$ node http.js
Server {
  maxHeaderSize: undefined,
  insecureHTTPParser: undefined,
  _events: [Object: null prototype] {
    request: [Function (anonymous)],
    connection: [Function: connectionListener]
  },
  _eventsCount: 2,
  _maxListeners: undefined,
  _connections: 0,
  _handle: null,
  _usingWorkers: false,
  _workers: [],
  _unref: false,
  allowHalfOpen: true,
  pauseOnConnect: false,
  httpAllowHalfOpen: false,
  timeout: 0,
  keepAliveTimeout: 5000,
  maxHeadersCount: null,
  maxRequestsPerSocket: 0,
  headersTimeout: 60000,
  requestTimeout: 0,
  [Symbol(IncomingMessage)]: [Function: IncomingMessage],
  [Symbol(ServerResponse)]: [Function: ServerResponse],
  [Symbol(kCapture)]: false,
  [Symbol(async_id_symbol)]: -1
}
Local Server Listen

Serverクラスのオブジェクトということがわかる。

Sample/nodejs/http/createServer/src/http at master · bg1bgst333/Sample · GitHub