我们先到手册上看看: 上面很明显就写着返回一个对象. 再来看看util模块, 废话不哦多说,先上一点代码: /** * Created by leigood on 2016/8/13. */ var http = require('http'); var url = require('url'); var util = require('util'); var server = http.createServer(function(req,res){ res.writeHead(200,{"Co…
node比客户端浏览器的js强的地方之一就是他的文件操作模块,可以直接对系统的文件进行操作 再打开来看下是否发生了变化,由此可见node的强大的地方了.. 实际代码如下所示: /** * Created by leigood on 2016/8/30. */ var fs = require('fs'); var exec = require('child_process').exec; //打开 var data = fs.readFileSync('day.txt','utf-8'); //…
目录结构如下所示: /** * Created by leigood on 2016/8/13. */ var http = require("http"); var fs = require("fs"); http.createServer(function(req,res){ res.writeHead(200,{'Content-Type':'text/html'}); var data = fs.readFileSync("1.html"…
我们来升级玩玩,废话不多说,代码如下所示: /** * Created by leigood on 2016/8/12. */ var net = require('net'); var ChatSrever = net.createServer(); clinetList = []; ChatSrever.on("connection",function(client){ client.name = client.remoteAddress + ":" + cli…
我们理论知识太多还不如实战,我们来写一个可以通过telnet腾讯的小玩意玩玩: var net = require('net'); var ChatServer = net.createServer(); clinetList = []; ChatServer.on("connection",function(client){ clinetList.push(client); client.write('hello world leigood \n\r'); client.on(&qu…