Skip to content

Latest commit

 

History

History
38 lines (30 loc) · 795 Bytes

nodejs.md

File metadata and controls

38 lines (30 loc) · 795 Bytes

keywords

  • asynchronous 异步
  • event-driven 事件驱动
  • JavaScript runtime js运行时

simple tutorial

Simple http server creation

Two method to create http server,below:

  1. 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);
  2. 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);

http

http.ServerResponse