nodejs实现简单的http请求

// 1、引入模块
var http = require('http');
var fs = require('fs');
// 2、搭建服务器
var server = http.createServer(function(request, response) {
    console.log(request.url)
    response.writeHead(200, {
        'content-type': 'text/html;charset:utf-8'
    })
    response.write(fs.readFileSync('./index.html'));
    response.end();
})
server.listen(8080, function() {
    console.log('端口号localhost:' + server.address().port)
});

你可能感兴趣的:(nodejs)