node 简单的链接服务

来源:互联网 发布:中国人全世界种菜 知乎 编辑:程序博客网 时间:2024/05/17 17:39
day01.js
/* * 引用需要的模块(require) **/var http = require("http");//http模块,主要用于http的处理和解析//createServer方法能够创建一个服务var myApp = http.createServer(function(request,response){//200 表示相应成功response.writeHead(200,{"Content-Type" : "text/html;charset = utf-8"});//向页面写入想要写入的东西response.write("<div style='color:red'>测试002</div>");//服务器结束endresponse.end("关闭服务器");});//监听的端口myApp.listen(8000);//控制台输出console.info("服务器启动成功");


黑窗口切入到当前文件夹 命令行输入 node day01.js

浏览器打开输入 http://127.0.0.1:8000/