转载和积累系列 - Node学习 - 1. 创建简单的HTTP服务器

来源:互联网 发布:淘宝书城书店护士资格 编辑:程序博客网 时间:2024/06/14 18:40
  • NodeJS下载:http://nodejs.org
  • 在windows下安装完毕之后,直接在cmd中直接运行node进入命令行模式

     

 

  • 输出一行Hello World

    

 

  • 创建一个简单的Node Http服务器,hello.js
var http = require("http");var httpInfo = function (req, res) {res.writeHead(200, {'Content-Type' : 'text/html'});res.write("Hello");res.end("Hello");}http.createServer(httpInfo).listen(8080);console.log("Http Server is Listening at port 8080");
  • 运行node

    

 

  • 通过浏览器 http://127.0.0.1:8080访问一下