API利用法
Node.jsのAPI利用法を以下に示します。
HTTPサーバー
Section titled “HTTPサーバー”Node.jsでは、http
モジュールを使用してHTTPサーバーを作成できます。
const http = require('http');
const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Hello World\n');});
server.listen(3000, '127.0.0.1', () => { console.log('Server running at http://127.0.0.1:3000/');});