node.js http模块 简单例子

// 导入 node的原生http模块

const http = require('http');

 

// 创建 server服务端对象,请求与响应由回调函数处理

const server = http.createServer( (req, res) => {

    res.writeHead(200, {'Content-Type': 'text/html'});

    res.end('<h1>Hello world!</h1>');

});

 

// 监听3000端口的通信

server.listen(3000, () => {

    console.log('Listening on port 3000...');

});

posted @ 2019-12-25 09:25  jack·wang  阅读(245)  评论(0)    收藏  举报