node的http请求

 1 //node的http服务
 2 
 3 'use strict'
 4 var http = require('http')
 5 var server = http.createServer(function (request,response) {
 6     response.writeHead(200,{'Content-Type':'text/html'});
 7     response.end('<h1>我的第一个node Http程序请求</h1>')
 8 })
 9 server.listen(8080);
10 console.log('Server is running at http://127.0.0.1:8080/')
11 
12 // 运行结果:
13 // $ node hello.js
14 // Server is running at http://127.0.0.1:8080/
15 // 不关闭命令提示符,打开浏览器:localhsot:8080得到服务器响应内容:我的第一个node Http程序请求
原文地址:https://www.cnblogs.com/yangguoe/p/9764317.html