- asynchronous 异步
- event-driven 事件驱动
- JavaScript runtime js运行时
Two method to create http server,below:
-
use http.createServer() function
const http = require('http'); const server = http.createServer((req,res) => { console.log(req.headers); console.log(req.url); res.end('success'); }); server.listen(3000);
-
use http.Server constructor
const http = require('http'); const server = new http.Server(); server.on('request',(req,res) => { console.log(req.headers); console.log(req.url); res.end('success'); }); server.listen(3000);