摘要:
//1:加载相应的模块 http url fs mysqlconst http = require("http");const url = require("url");const fs = require("fs");const mysql = require("mysql");//2:创建连接池 阅读全文
摘要:
const mysql = require("mysql");var conn = mysql.createConnection({ host:"127.0.0.1", user:'root', password:'', database:'jd', port:3306});//2:发送sql//c 阅读全文
摘要:
//#使用nodejs编写动态的web服务器//1:加载需要模块 fs http urlconst fs = require("fs");const http = require("http");const url = require("url"); //2:创建web服务器//3:绑定端口var 阅读全文
摘要:
//功能:创建web服务器接收客户请求// http://127.0.0.1:8080/index 准备// http://127.0.0.1:8080/news 准备// public/index.html// public/news.html// public/404.html//1:加载htt 阅读全文
摘要:
//1:加载http模块 httpconst http = require("http");//2:创建http 服务器var server = http.createServer();//3:为服务器绑定监听端口 8080//端品有效范围: 1023 65535server.listen(8080 阅读全文
摘要:
console.log("1:开始读成取文件内容...");fs.readFile('./public/2.log',function(err,data){ if(err){ console.log("文件读取出现错误"); //console.log(err);错误的话返回code:ENOENT 阅读全文
摘要:
//1:字节 byte//1024b = 1kb [千字节]//1024kb = 1mb [兆字节]//1024mb = 1gb [吉字节]//1024gb = 1tb [梯]//1024tb = 1pb //1:创建大小为1024字节缓冲区var buf1 = Buffer.alloc(1024) 阅读全文
摘要:
const url = require("url");var u = "https://www.jd.com:443/ad/index?uname=qd";//将url解析js对象var obj = url.parse(u);console.log(obj);//true:指定querystring 阅读全文
摘要:
const qs =require('querystring'); var str="uname=tom&upwd=123&pno=33&kw=js;" //查询字符串转成对象 var obj=qs.parse(str); console.log(obj) // 输出JS对象{uname:'tom' 阅读全文
摘要:
JS文件中const fs = require("fs");console.log("开始进入文件读取..");//同步的写入var data = fs.readFileSync("./public/1.html"); console.log("文件读取完成");console.log(data); 阅读全文